posted 17 years ago
Hi Praveen,
In my evaluation, I see the same .
here is the explanation,
class C
{
public static void main(String a[])
{
C c1=new C(); // OBJONE: here object OBJONE is getting created
C c2=m1(c1); // here c2 refers OBJTWO
C c3=new C(); //OBJTHREE: ct is created
c2=c3; //6 // c2 now refers OBJTHREE
anothermethod();
}
static C m1(C ob1){ // ob1 refers to OBJONE
ob1 =new C(); //now ob1 is refering a new object say OBJTWO
return ob1; // OBJTWO is returned
}
}
so at the line 6, c1 refers OBJONE , nothing refers OBJTWO because ob1 is a method local variable, and its life time is only when the method is getting executed..so OBJTWO is eligible for GC,
OBJTHREE is referenced by C2 C3.
am i right praveen? Please give your explanation.
[ September 06, 2007: Message edited by: Thiru Mu ]