fxfeiyi

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

          垃圾回收經(jīng)典問題

          Posted on 2006-08-04 21:19 fxfeiyi 閱讀(379) 評論(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).


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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 杭锦后旗| 河东区| 竹溪县| 扬州市| 岳阳市| 吴桥县| 溆浦县| 岳池县| 洪雅县| 井研县| 黔西县| 福贡县| 冀州市| 五家渠市| 二连浩特市| 阳泉市| 屯门区| 美姑县| 得荣县| 宁阳县| 准格尔旗| 玛曲县| 招远市| 保亭| 得荣县| 巴彦淖尔市| 东光县| 中牟县| 崇礼县| 义马市| 安远县| 景东| 左权县| 通山县| 拉萨市| 铁力市| 都昌县| 金门县| 鄢陵县| 将乐县| 界首市|