Originally posted by Parag Kale:
Hi!
I found this on one of the mock exams.
After the following code is run, the output is 10,0,20 and that is also supposed the be the right answer. But i think the answer should be 10, 0, 30. Can somebody explain what really happens to the value of v.i, in detail ?
Parag,
You have to walk through it carefully you'll get tripped up. I think here's what's confusing you: When the method amethod() calls the another() method, it is sending a
reference to the v (ValHold) object. The first thing another() does is reset i to 20. It is resetting the
original object's value since it only passed a reference to the object, not the object itself nor a copy of the object. If you read the Campfire's "Cup Size" essay, you'll see my point. Following that logic through, you'll see that i is really 20 when it is finally printed out at the end of amethod().
[This message has been edited by Rebecca Pickett (edited April 10, 2001).]