Hi sola,
Look at the question once more.
"When is the Integer object, created in line 3, eligible for garbage collection? "
Itz not asking about the object which is pointed by "x"
[ "x" is infact the copy of the orginal reference ] before the method is called.
-------------------------------------
Lets modify the code to make it more clear.
class A {
public static void main(
String args[]) {
X b = new X();
String n = "aryan";
// The copy of the reference "n" is passed to the method m().
// The orginal "n" points to the string "aryan" . rite ?
b.m(n);
}
}
public class X {
public void m(Object x) {
// remember "x" is the copy of "n"
// Now "x" will point to the new object, no more to the orginal String object it was pointing.
x = new Integer(99);
// now "y" also point to the same object pointed by "x"
// [ an instance of Integer ]
Integer y = (Integer)x;
// now the above object created got only one reference ie "x"
y = null;
System.out.println("x is" + x);
// "x" is going to die, now , since its life period ends after the
// method call. V r talking about the "x", which is a copy of
// "n".
// So the "x" dies, Integer object is orphaned, and Garbage collector
// gets a an orphan to sweep, and its happy. [ the String object is
// still living happly some where in the memory, coz, it still has
// a reference, "n".
// So question was abt the Integer object not abt the String object.
// now u know the answer .. rite ?
}
}
[This message has been edited by Jon Aryan (edited October 08, 2000).]