1. class Bar { }
1. class Test {
2. Bar doBar() {
3. Bar b = new Bar();
4. return b;
5. }
6. public static void main (String args[]) {
7. Test t = new Test();
8. Bar newBar = t.doBar();
9. System.out.println(“newBar”);
10. newBar = new Bar();
11. System.out.println(“finishing”);
12. }
13. }At what point is the Bar object, created on line 3, eligible for garbage collection?A. After line 8.
B. After line 10.
C. After line 4, when doBar() completes.
D. After line 11, when main() completes.
应该选哪个,为什么?谢谢了,在线等~~~

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【sxzhliang】截止到2008-07-24 08:54:30的历史汇总数据(不包括此帖):
    发帖的总数量:7                        发帖的总分数:90                       每贴平均分数:12                       
    回帖的总数量:6                        得分贴总数量:0                        回帖的得分率:0%                       
    结贴的总数量:7                        结贴的总分数:90                       
    无满意结贴数:1                        无满意结贴分:20                       
    未结的帖子数:0                        未结的总分数:0                        
    结贴的百分比:100.00%               结分的百分比:100.00%                  
    无满意结贴率:14.29 %               无满意结分率:22.22 %                  
    敬礼!
      

  2.   

    我认为是B。第4句返回了一个指向b的引用,而第10句之后newBar指向了一个新的Bar对象,再没有了b的引用,因此这时b可以被回收
      

  3.   

    应该是D
    没有给他赋值null,所以需要到方法结束的时候
      

  4.   

    选B
    newBar = new Bar();之后在第三行创建的对象已经无法引用到,成为垃圾.
      

  5.   

    权威答案:B,解释见 2楼 4楼。
    5楼注意:eligible for garbage collection? 翻译为“具备垃圾回收的条件”。