posted 18 years ago
When you passing i (which is 10 at that moment) to the p.amethod(i); method, you realy passing a copy of bit-pattern of i.
(00000000000000000000000000001010) - bin
So, next, inside p.amethod(i); you do x=x*2;. The value of x was 10 and now it became 20 as you can guess. But, "i" still has value of 10, couse x is just a copy of i, remember?
Next, j=j*2;. Well, j was 20 now it is 40. Simple. You accessing static variable (j) from instance method and, for example, IntelliJ IDEA will complain about it, but it's legal.
Next, p.amethod(i); is over - this meens:
- x variable is gone
- j has value of 40
- i has value of 10
So, the output is just like it should be, yeah?
[ July 08, 2005: Message edited by: George Bolyuba ]
[ July 08, 2005: Message edited by: George Bolyuba ]
SCJP 1.4 (100%) Done.<br />SCJD (URLyBird 1.2.3 Started)