"SCJP 1.6版考題 108" 修訂間的差異

出自 陳富國維基館
前往: 導覽搜尋
(新頁面: Given: 11. class Snoochy { 12. Boochy booch; 13. public Snoochy(){booch = new Boochy(this);} 14 } 15. 16. class Boochy{ 17. Snoochy snooch; 18. public Boochy(Snoochy s){snooch...)
 
(無差異)

於 2013年3月30日 (六) 05:32 的最新修訂

Given:
11. class Snoochy {
12. Boochy booch;
13. public Snoochy(){booch = new Boochy(this);}
14 }
15.
16. class Boochy{
17. Snoochy snooch;
18. public Boochy(Snoochy s){snooch = s;}
19. }
And the statements.
21. public static void main(String[] args){
22. Snoochy snoog = new Snoochy();
23. snoog = null;
24. //more code here
25. }


Which statement is true about the objects referenced by snoog, snooch, 
and booch immediately after line 23 executes?
  A. None of these objects are eligible for garbage collection.
  B. Only the object referenced by booth is eligible for garbage collection.
  C. Only the object referenced by snoog is eligible for garbage collection.
  D. Only the object referenced by snooch is eligible for garbage collection.
  E. The objects referenced by snooch and booth are eligible for garbage collection. 

解答


Ans: E

解說: SCJP108-1.png

三個物件參考所參考到的物件都可被物件回收…最適當的答案是E
若外界(執行中的方法)沒有任何參考變數可以參考到物件,這個物件被視做可被回收的,
而這個物件也被稱做是isolated island(孤島/失落的物件)