Question: QUESTION 11 Given: 3. class Beta { } 4. class Alpha { 5. static Beta b1; 6. Beta b2; 7. } 8. public class Tester

QUESTION 11

Given: 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.b1because it's static. A, C, D, E, and F are incorrect based on the above. (OCA Objective 2.4)

REQUIRED

please explain why answer is correct and why not others ? explain in detail .

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!