SCJP 1.6版考題 099
出自 陳富國維基館
3. interface Animal{void makeNoise();} 4. class Horse implements Animal{ 5. Long weight = 1200L; 6. public void makeNoise(){System.out.println("whinny");} 7. } 8. public class lcelandic extends Horse{ 9. public void makeNoise(){System.out.println("vinny");} 10. public static void main(String[] args) { 11. Icelandic i1 = new lcelandic(); 12. Icelandic i2 = new lcelandic(); 13. Icelandic i3 = new lcelandic(); 14. i3 = i1; i1 = i2; i2 = null; i3 = i1; 15. } 16.} When line 14 is reached, how many objects are eligible for the garbage collector? A. 0 B. 1 C. 2 D. 3 E. 4 F. 6
解答
Ans: C
解說:
i3=i1,i3原本指向的物件可回收,i1=i2, i1原本指向的物件因被i3參考不能被回收,i2=null, i2指向的物件被i1參考不能回收,i3=i1,i3指向的物件可回收 可以畫圖來看比較清楚。
|