• 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
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Garbage collection

 
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This was the question I found in Jhon hunt's mock exam?
Q. 31
In the following code, which is the earliest statement, where the object originally held in e, may be garbage collected:
public class Test {
public static void main (String args []) {
Employee e = new Employee("Bob", 48);
e.calculatePay();
System.out.println(e.printDetails());
e = null;
e = new Employee("Denise", 36);
e.calculatePay();
System.out.println(e.printDetails());
}
}
Line 10
Line 11
Line 7
Line 8
Never
Select

Answer is Line 7
Can anybody explain how?
Thanks
Veena
 
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is my answer... others feel free to add or correct me if I am wrong...
I think the key here is the phrase "the object originally held in e" and that object is set to null in line 6, so in line 7, that object can be gc'ed.
It is a bit confusing because there is another new object that gets created in line 7 and stored in e. But this is another new object.
Hope that helps
[ July 31, 2002: Message edited by: Nate Johnson ]
 
Veena Pointi
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Nate,I didn't think about the new object.
Veena
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Veena,
Congratulations on becoming a ranch hand with your 31st post!
 
Veena Pointi
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Dan.But I really don't know anything about ranch hand member & other namings like bartender,how they are given?.Just know that newly registered member greenhorn member.
Veena
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Veena,
A greenhorn becomes a ranch hand after 30 posts. I noticed that you had 31 so I thought that I would offer my congratulations since you probably didn't even notice the change.
 
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Congratulations, Veena! In case you're curious...
 
Veena Pointi
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks ...
Anthony that discussion was pretty interesting & funny.I am really enjoying here in Javaranch.
JavaRanch great place to share Java knowledge & have fun.
Veena
 
The fastest and most reliable components of any system are those that are not there. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic