fxfeiyi

          JavaBlog
          posts - 2, comments - 0, trackbacks - 0, articles - 0
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          垃圾回收經典問題

          Posted on 2006-08-04 21:19 fxfeiyi 閱讀(378) 評論(0)  編輯  收藏 所屬分類: SCJP

          2. Given:

          class CardBoard {
          Short story = 5;
          CardBoard go(CardBoard cb) {
          cb = null;
          return cb;
          }
          public static void main(String[] args) {
          CardBoard c1 = new CardBoard();
          CardBoard c2 = new CardBoard();
          CardBoard c3 = c1.go(c2);
          c1 = null;
          // do Stuff
          }
          }

          When // doStuff is reached, how many objects are eligible for GC?

          A. 0
          B. 1
          C. 2
          D. Compilation fails.
          E. It is not possible to know.
          F. An exception is thrown at runtime.
          ---------------------------------------------
          > The object originally pointed to by c1 is eligible,
          > because you have no reference to it. You still have
          > a reference to the object pointed to by c2, because
          > Java is pass by value, so in "go", the parameter is
          > set to null, not c2. c3 never gets an object--it is
          > set to null immediately, because null is the return
          > value of c1.go(c2).


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 田阳县| 凤阳县| 交口县| 香港 | 璧山县| 安新县| 裕民县| 浠水县| 淳化县| 准格尔旗| 金华市| 新化县| 凌云县| 海南省| 彰化县| 宁夏| 资阳市| 廉江市| 沙湾县| 阿坝县| 成武县| 安泽县| 伽师县| 金秀| 上林县| 徐州市| 乳源| 华宁县| 浦城县| 桃园市| 荣成市| 行唐县| 会东县| 淳安县| 安岳县| 斗六市| 道真| 吉安市| 河南省| 兴山县| 富川|