• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

4test..Mock Problem

 
Mukti Bajaj
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
What will be the answer for the code below....Answer given:Line 7
But, according to me the answer should have been : Line 10
1.public class Test {
2.public static void main (String args []) {
3.Employee e = new Employee("Bob", 48);
4.e.calculatePay();
5.System.out.println(e.printDetails());
6.e = null;
7.e = new Employee("Denise", 36);
8.e.calculatePay();
9.System.out.println(e.printDetails());
10.}
11.}
Can someone pelase clarify.
Thanks
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am assuming the question is when will the object originally created by e be eligble for garbage collection.
If this is the question, then the answer is at line 7. The reason is that at line 7, the object Employee("Bob",48) no longer has any references. So if nothing is pointing to it, it can be garbage collected.
Remember it is the object that e is pointing to that is being garbage collected, not the reference variable e.
Bill
 
Mukti Bajaj
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks Bill, ...i got it now.
Mukti
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic