This week's book giveaways are in the Cloud/Virtualization and Go forums.
We're giving away four copies each of Cloud Native Transformation: Practical Patterns for Innovation and The Go Workshop and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native Transformation: Practical Patterns for InnovationE this week in the Cloud/Virtualization forum
or The Go Workshop in the Go forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

Garbage collection

 
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
Congratulations, Veena! In case you're curious...
 
Veena Pointi
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
  • 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
 
What's wrong? Where are you going? Stop! Read this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!