<AptiCode/>

Question 763: class Bar { } class Test { Bar doBar() { Bar b = new Bar(); /* Line 6 */ return b; /* Line 7 */ } public static void main (String args[]) { Test t = new Test(); /* Line 11 */ Bar newBar = t.doBar(); /* Line 12 */ System.out.println("newBar"); newBar = new Bar(); /* Line 14 */ System.out.println("finishing"); /* Line 15 */ } }At what point is theBarobject, created on line 6, eligible for garbage collection?

tcs
wipro
infosys
general
aptitude
garbage-collections
java-programming

Option B is correct. All references to theBarobject created on line 6 are destroyed when a new reference to a newBarobject is assigned to the variablenewBaron line 14. Therefore theBarobject, created on line 6, is eligible for garbage collection after line 14.Option A is wrong. This actually protects the object from garbage collection.Option C is wrong. Because the reference in thedoBar()method is returned on line 7 and is stored innewBaron line 12. This preserver the object created on line 6.Option D is wrong. Not applicable because the object is eligible for garbage collection after line 14.