Vonique Leary wrote:
Look at the "doStuff" method. "B = new Cat();" Remember what that means? B has it's bit of paper wiped and a new address (reference, bit pattern, call it what you will) written on it. This points at a new Cat on the heap.
A is still pointing at the old Cat. A's bit of paper (address/reference/bit pattern) has not been changed.
Try as I might I cannot get this question answered, and I think it is the key to the entire confusion for me:
In the method doStuff, B is just the parameter is it not? A is getting passed to it. So when you say that B has it's bit of paper wiped and a new address aren't we really talking about A? Because then you say A is still pointing at the old Cat. So I will ask again, there is an A (passed as an argument to the method to act as the B parameter) pointing to a new Cat, but then you say A is still pointing to the new Cat?
Am I confused about the method scope? Is it because A in the doStuff method goes out of scope?