java题求解释

来源:百度知道 编辑:UC知道 时间:2024/06/05 07:23:32
1)public class X{
2) public Object m(){
3) Object o=new Float(3.14F);
4) Object[] oa=new Object[];
5) oa[0]=o;
6) o=null;
7) oa[0]=null;
8) System.out.println(oa[0]);
9) }
10) }
which line is the earliest point the object a refered is definitely elibile to be garbage collectioned?
A. After line 4
B. After line 5
C.After line 6
D.After line 7
E.After line 9

为什么呢?
为什么是 7 不是 6

首先你这个题目就有错误 Object[] oa=new Object[]; 这个明显就定错的 那有这样写的 右边不给出数组的范围
1)public class X{
2) public Object m(){
3) Object o=new Float(3.14F);
4) Object[] oa=new Object[1]; //改了
5) oa[0]=o;
6) o=null;
7) oa[0]=null;
8) System.out.println(oa[0]);
9) }
10) }
因为在第六行的时候 oa[0]还指向 原O的对象 所以不能是六 只有在第七行以后给空以后才能回收

7

d