Hi all, please ignore the first post. I had accidentally keyed wrongly. Here i am,
public class A{
public static void main(String[] args) {
A a = new A();
A b = new A();
A c = A();
a.aob = b; //line 6
b.aob = a;//line 7
c.aob = a.aob; //line 8
A d=new A().aob = new A(); //line 9
c=b; //line 10
c.aob = null; //line 11
System.gc();
}
}
How many objects are eligible for GC after executing statement "c.aob=null"?
The answer is 2.
Here my drawing,
a -> A (obj1)
b -> A (obj2)
c -> A (obj3)
then
a -> A (obj1) -> A (obj2) //line 6
b -> A (obj2) -> A (obj1) //line 7
c -> A (obj3) -> A (obj2) //line 8
d -> A (obj4) -> A (obj5) //line 9
c -> A (obj2) //line 10, obj3 GCed here!!
c -> A (obj2) -> null //line 11
Where is another object??
Please help..
Regards,
Edmen