Programming Homework Help

Programming Homework Help. garbage collection, java, static

Hi, I am going through SCJP material and I have a doubt regarding a question I came across in that material:

3. class Beta { }
4. class Alpha {
5. static Beta b1;
6. Beta b2;
7. }
8. public class Tester {
9. public static void main(String[] args) {
10. Beta b1 = new Beta(); Beta b2 = new Beta();
11. Alpha a1 = new Alpha(); Alpha a2 = new Alpha();
12. a1.b1 = b1;
13. a1.b2 = b1;
14. a2.b2 = b2;
15. a1 = null; b1 = null; b2 = null;
16. // do stuff
17. }
18. }
When line 16 is reached, how many objects will be eligible for garbage collection?
A. 0
B. 1
C. 2
D. 3
E. 4
F. 5
Answer:
® ✓ 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.

For this question I thought the answer would be 4 at first, since a1 is declared NULL. This a1 and a2 has two other objects b1 and b2, which are made to point to the other two objects b1 and b2. But they are also declared NULL, so I thought a1, a1’s b1, b2, a2’s b2 will also become NULL.

Please help me understand this answer B.

Thanks,

Programming Homework Help

 
"Our Prices Start at $11.99. As Our First Client, Use Coupon Code GET15 to claim 15% Discount This Month!!"