class TestA {
TestB b;
TestA() {
b = new TestB(this);
}
}
class TestB {
TestA a;
TestB(TestA a) {
this.a = a;
}
}
class TestAll {
public static void main (String args[]) {
new TestAll().makeThings();
// ...code continues on
}
void makeThings() {
TestA test = new TestA();
}
}
Which two statements are true after line 15, before main completes? (Choose two)
A. Line 15 causes a stack overflow.
B. An exception is thrown at runtime.
C. The object referenced by a is eligible for garbage collection.
D. The object referenced by b is eligible for garbage collection.
E. The object referenced by a is not eligible for garbage collection.
F. The object referenced by b is not eligible for garbage collection.
答案是c,d。它是这样解释的:This is a typical example of the island of isolation. On line 15, the two objects TestA and TestB have a eference to one an other. Therefore, the correct answers are C. and D. A key point to remember is that an object that is referenced by another object can be eligible for
garbage collection if the two objects form an island of isolated objects.