我在SCJP准备网站上经历过这个问题。 答案A如何正确?java垃圾回收
对于由a,b,aa引用的对象,在标有“//某些代码在此处出现 ”这一行的情况如何?
class A {
private B b;
public A() {
this.b = new B(this);
}
}
class B {
private A a;
public B(A a) {
this.a = a;
}
}
public class Test {
public static void main(String args[]) {
A aa = new A();
aa = null;
// some code goes here
}
}
A) The objects referenced by a and b are eligible for garbage collection.
B) None of these objects are eligible for garbage collection.
C) Only the object referenced by "a" is eligible for garbage collection.
D) Only the object referenced by "b" is eligible for garbage collection.
E) Only the object referenced by "aa" is eligible for garbage collection.
答案:A