Hello everyone,
I am new to the forum and this is my first post.
I would really appreciate if someone can help me .
Question 4
class I {
private I other;
public void other(I i) {other = i;}
}
class J {
private void m1() {
I i1 = new I(), i2 = new I();
I i3 = new I(), i4 = new I();
i1.other(i3); i2.other(i1);
i3.other(i2); i4.other(i4);
}
public static void main (String[] args) {
new J().m1();
}}
Which object is not eligible for garbage collection after method m1
returns? Ans: g. None of the above
********
i did understand that
I i1 = new I(), i2 = new I();
I i3 = new I(), i4 = new I();
creates 4 objects on the heap of type I, refered by i1,i2,i3,i4.
i1.other(i3); i2.other(i1);
i3.other(i2); i4.other(i4);
now i don't get this part.
i1.other referes to the same object as i3 does
i2.other referes to the same object as i1 does
i3.other referes to the same object as i2 does
i4.other referes to itself
but does it mean i1,i2,i3,and i4 do not refere to any object now?
these references still refer to the original objects right?
[/LIST][LIST]