Is that means the reference of Q (q1) in method m1 pass into m2, assign to a instance reference ?
Well, the answer said :
If method m2 causes a reference to be saved for each object that is passed in as an argument,...
It does not say how it will do it (it can be assigned to instance variable, or it can be assigned to a static variable, or it can even be assigned to a local variable).
However, I think I can see the ambiguity in this question which might confuses Jack. Dan's given answer above only said that the "saving" happened to each object passed to m2. It does not say "how long" it will be saved, particuarly, it is not clear that when line 3 begins, whether those saved references remains unmodified.
So, in a way Jack's interpretation of m2 can be true, because as far as m2 concerns, it always saves the reference of each object passed to it (eventhough only the last one remains saved/unmodified).
Even if m2 saves all the references passed to it without modifying previous saved references, one can also write code where before line 3 begins, another
thread is modifying the references (saved in m2) causing the corresponding objects to be eligible for GC.
Perhaps the wording can be made so it is clear that all references passed to and saved in m2 are not modified when line 3 begins?
Does it make sense? Or am I getting to picky?
P.S. : I think this is a good question of Dan, for it is not only
testing knowledge about GC, but also test one's ability to draw the correct conclusion from a given statement (if method m2...) rather than merely reading the code.
[ January 22, 2004: Message edited by: David Hadiprijanto ]