hi Tanuja
In
java when we pass an object reference as a paramter in a method call..the copy of the reference value is actually passed rather than the reference itself..
so in the call another(v.i,i)...we are passing a copy of the reference value(ie. the address stored in the v). to the method.So the actual parameter
(Valhold v) in the method void another(ValHold v, int i) is the copy of the reference value in the formal parmeter in the method call.
so,
in the call another(v.i,i)--v.i=30
in the method
--- we are changing the value at the same location by the statement v.i=20;
so now the actual value has been changed.
but then we are creating another object of valhold v which is not same as the previous one..
ie. ValHold v = new ValHold();
and now v.i=30;
makes another object with it's i= 30.
hence , line 2 prints 20 and 3 prints 30.
I hope this is confusing.
swapna