• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

SCJP......Garbage collection

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 = 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.
Answer:
g is correct.....

i am unable to underatand...can any one help me
 
Ranch Hand
Posts: 37
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
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;
System.out.println(""+e3.e);
e1.e = e3;
System.out.println(""+e1.e);
e2 = null;
System.out.println(""+e2);
e3 = null;
System.out.println(""+e3);
e2.e = e1;//here it will gives the NullPointerException
//Because you are nulling the reference variable e2 at line11.

System.out.println(""+e2.e);
e1 = null;
} }
 
Anything worth doing well is worth doing poorly first. Just look at this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic