Hi, I got it from K&B 5 study guide and i modified a bit.
class Island
{
Island i;
public static void main(
String args[])
{
Island i1=new Island();
Island i2=new Island();
Island i3=new Island();
Island i4=new Island();
i1.i=i2;
i2.i=i3;
i3.i=i1;
i4.i=i3;
i3=null;
i2=null;
i1=null;
}
}
How many objects are eligible for GC?
my guess is 3. since i4 is not null islands of objects are still referring each other and they are not eligible for Gc.so only i1,i2,i3 are eligible for Gc.
Am i got the point?
Please do correct me if i am wrong.
Preparing
Scjp 1.5