Well I check the code, its a question given in the Kathy Sierra book under Self Test-12th question.
I am again posting the question with options and answer.
Given:
1. class Eco {
2. public static void main(String[] args) {
3. Eco e1 = new Eco();
4. Eco e2 = new Eco();
5. Eco e3 = new Eco();
6. e3.e = e2;
7. e1.e = e3;
8. e2 = null;
9. e3 = null;
10. e2.e = el;
11. e1 = null;
12. }
13. Eco e;
14. }
At what point is only a single object eligible for GC?
a)After line 8 runs.
b)After line 9 runs.
c)After line 10 runs.
d)After line 11 runs.
e)Compilation fails.
f)Never in this program.
g)An exception is thrown at runtime
ANSWER:
G is correct. An error at line 10 causes a NullPointerException to be thrown because e2 was set to null in line 8, If line 10 was moved between lines 7 and 8, then F would be correct, because until the last reference is nulled none of the objects is eligible, and once the last reference is nulled, all three are eligible.