Kamil Wojcik wrote:We know that the answer will be 10020, but can someone explain, why at the and we get 20? Thanks
At line 20, the another() method changes v.i to 20. Remember, when you pass an Object reference to a method, you pass a copy of the reference, not a separate copy of the object. So now, v.i points to the same v that was declared in line 12. So when the another() method completes and we resume at line 15, the value of v.i has been changed to 20. Does that make sense?
Hey when you pass a referance variable to a method you are not only passing the address of that referance variable but that is copy of that referance variable address.
This means that you are passing copy of referance variable to ValHold v.
Then you are changing that value to vh(another object) The previous referace object is still same uneffected.
Remember you can always change the value of the passing object but you can't change the passing object to refer to other object.
Hey when you pass a referance variable to a method you are not only passing the address of that referance variable but that is copy of that referance variable address.
This means that you are passing copy of referance variable to ValHold v.
Then you are changing that value to vh(another object) The previous referace object is still same uneffected.
Remember you can always change the value of the passing object but you can't change the passing object to refer to other object.
Answer is abc.
Post by:autobot
LOOK! OVER THERE! (yoink) your tiny ad is now my tiny ad.
a bit of art, as a gift, that will fit in a stocking