wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes 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 "garbage collection" Watch "garbage collection" New topic
Author

garbage collection

srinivas sridaragaddi
Ranch Hand

Joined: Jul 24, 2007
Posts: 225
hi,




here i am not getting as to what is e3.e.i understand that e3 is a
reference pointing to an Eco object and e is also a reference
so how to interpret e3.e and please explain as to how many object
are eligible for garbage collection my answer is 2 objects are
eligible.


SCJP 5.0<br /> <br />"Skills are started with learning and mastered with improvement. Nothing is hereditary except death" BUDDHA...
Thirumalai Muthu
Ranch Hand

Joined: Oct 07, 2007
Posts: 75
class Eco {
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;//line1
e3 = null;
e2.e = e1;//line3
e1 = null;
}
Eco e;//line 5
}




This program will have a Nullpointer Exception created because at Line 1 you are assigning "null" to e2 and after that at Line 3 you are using the dot operator on a null reference.So This creates a null Pointer Exception.

In Line 5:
Here 'e' is an instance variable of class Eco.So all the objects that you create for Class Eco will have 'e' in it.
[ October 22, 2007: Message edited by: Thirumalai Muthu ]

SCJP 5
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: garbage collection