Hi Kapil,
Java passes by reference. That means that you can't change the reference variable but you can change contents of the object that the reference is pointing to. In this case we have:
1. Inside o.amethod().
local variable i set to 99
local variable v created and i member variable set to 30
call another method sending v and i
2. Inside another()
local variable i set to 0
member variable i of passed reference v set to 20 local variable vh created with default member variable i set to 10
local variable v set to point to local variable vh
print out local variable v.i --> 10
print out local variable i --> 0
3. Back from another() call (inside amethod())
print out local variable v.i --> 20
The key is that we have changed the contents (state) of the passed variable v but JVM doesn't allow us to change what v points to! This is a concept that
MUST be mastered to be able to program efficiently in Java!
Regards,
Manfred.