Hi Kamesh,
I've added comments to your example to explain what's happening.
The thing to remember is that
Java passes everything as a copy of the original
value. If you pass a primitive type; a copy of that type and value is created and given to the method. If you pass an object reference, a copy of the object reference is given to the method.
A copy of an object reference still points to the original object. Which is why
v.i = 20 changes the value in the ValHold object used by
aMethod. When you created
vh you created a new ValHold object. Assigning
vh to
v changed the
value of the object reference in the method
another BUT has no effect on the original object reference created in
aMethod.
Hope that helps.
------------------
Jane