作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
SCJP 测试题:
class A{
A aob;
public static void main(String args[]){
A a=new A();
A b=new A();
A c=new A();
a.aob=b;
b.aob=a;
c.aob=a.aob;
A d=new A().aob=new A();
c=b;
c.aob=null;
System.gc();
}
}
问题:c.aob=null
执行后,有多少对象符合垃圾回收条件。
我认为是 1,但正确答案是 2。有什么问题吗?
最佳答案
我通过谷歌搜索找到了this thread .
The first object is the one referenced originally by c.
A a= new A();
A b= new A();
A c= new A();
a.aob=b;
b.aob=a;
c.aob=a.aob;
A d= new A().aob=new A();
c=b; //(1)It becomes eligible at (1).
The other object eligible for GC is at statement
A d=new A().aob=new A();
Here the object created in the text in bold will be eligible for GC. The object in italicized text will be assigned to d.
关于java - SCJP测试题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1900443/
我是一名优秀的程序员,十分优秀!