This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

garbage collection

 
srinivas sridaragaddi
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Thirumalai Muthu
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic