java - working of static in following code -
class test { static int x = 11; private int y = 33; public void method(int x) { test t = new test(); this.x = 22; y = 44; system.out.println(test.x); system.out.println(t.x); system.out.println(t.y); system.out.println(y); } public static void main(string args[]) { test t = new test(); t.method(5); } } here code ok , gives output like: 22 22 33 44
but don 't understand:
why
test.xisn't11, give output like:11 22 33 44why
t.y,yisn't 44 , 44 , gives output like:11 22 44 44why
t.method(5)not executed in code?
the difference between static field , instance field static field not instance-dependent.
look here:
static int x = 11; private int y = 33; the static field x same every instance of test while field of y instance specific. that's why see these results.
Comments
Post a Comment