File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes SCJP......Garbage collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "SCJP......Garbage collection" Watch "SCJP......Garbage collection" New topic

SCJP......Garbage collection

srinibash udayasingh

Joined: Jul 09, 2007
Posts: 22
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 = e1;
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.
g is correct.....

i am unable to underatand...can any one help me
Ramu Valivarthi
Ranch Hand

Joined: Apr 24, 2007
Posts: 37

please go thru the following code.

class Eco {
Eco e;
public static void main(String[] args) {
Eco e1 = new Eco();
Eco e2 = new Eco();
Eco e3 = new Eco();
e3.e = e2;
e1.e = e3;
e2 = null;
e3 = null;
e2.e = e1;//here it will gives the NullPointerException
//Because you are nulling the reference variable e2 at line11.

e1 = null;
} }
I agree. Here's the link:
subject: SCJP......Garbage collection
jQuery in Action, 3rd edition