Here is my impression of which objects are created and how the references relate to them:
When line 16 is reached, how many objects will be eligible for garbage collection?
I selected D
The answer says that "B is correct. It should be clear that there is still a reference to the object referred to by a2, and that there is still a reference to the object referred to by a2.b2. What might be less clear is that you can still access the other Beta object through the static variable a2.b1 - because it's static" (K & B, 2000-something, p. 285).
What am I missing here? 0_o
*** Also which b1 and b2 are set to null? The class variable of Alpha and its instance variables or the variables declared in main and their instances?
I agree with the answer if the GC check was at line 14(I would suggest you take a crack at it again!), but line 16 looks like out of scope of main() method...so shouldn't all the 4 objects be available for GC at line 16?
Praveen Kumar M K
Joined: Jul 03, 2011
You could try with this, it will give more clarity.