Which of the three objects, A, B or C, is not eligible for garbage collection when method m2 begins to execute? a. A b. B c. C d. None of the above Answer is C... I thought every object is eligible for GC after the method has finished (in this case method m1) ???
The answer given is correct, "A" looses its reference when (i1 = i3) is executed and "B" looses its reference when i2 = i3 is executed, the remaining object is "C" which has three references on it (i1, i2, i3). Note also that "A", "B" and "C" are member objects, they'll loose their reference only after new J().m1(); finishes, executing m2() has no effect at all.
- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. <br />- What truth? <br />- That there is no spoon!!!