posted 20 years ago
First off we I'm assuming you understand the order of the "System.out"s, if not just let us know.
So now we have:
1)at line 23 we create a new ValHold object vh which has vh.i=10
at line 24 we use our new ValHold object vh created at line 23 and set v=vh
so now v.i=10
2)in method another() i was passed in with value of 99
but we immediately set i=0 at line 21
3)at line 16 we pass v into method another() and v.i=30 at this point
when we pass objects as parameters we are actually passing a copy of the reference
so at line 22 when v.i=20 that will also apply to the v object in the method amethod()
at line 24 we set method anonther()'s v to point to a diferent object, this does does not affect method amethod()'s v though
so at line 17 v.i=20
Hope that makes sense.