posted 21 years ago
1 public class X {
2 public void m(Object x) {
3 x = new Integer(99); // x is created
4 Integer y = (Integer)x; // y points to same object as x
5 y = null; // y is set to null, x still points to same object
6 System.out.println("x is" + x);
7 } //x leaves scope
8 }
When is the Integer object, created in line 3, eligible for garbage collection?
A) never
B) just after line 4
C) just after line 5
D) just after line 6 (that is, as the method returns)
E) when the calling method sets the argument it passed into this method to null
I think the answer is D, see comments above.
Can someone confirm this?