The following Q is from Kathy's book on SCJP1.4
After line 6 runs. how many objects are eligible for garbage collection?
A. 0
B. 1
C. 2
D. 3
E. 4
Answer given
10. B. By the time line 6 has run, the only object without a reference is the one generated
as a result of line 4. Remember that “
Java is pass by value,” so the reference variable x is not
affected by the m1() method.
My answer is C. I completely agree with Kathy's answer and explanation given above. But what about the object created in the method m1()? Isn't that also eligible for GC as no
thread can reach it?
I would like to hear from Kathy.
Thanks in advance,
Sarma