I am doing assignment questions given at end of SCJP book. Have a look at following code snippet:
The question is how many objects are available for GC at end ? The answer is 1. Can someone please (if possible with a diagram) explain how? I can see that 4 distinct objects (2 of Beta type and 2 of Alpha type) have been created on the heap. What do we mean when we say ? And in the end we are setting a1, b1, b2 to null. Then how come only 1 object is available for GC? A simple clear-cut explanation would be really helpful.