Love Java,Love China!

          2008年5月25日

          when upcasting .....

           1// codes start
           2class base{//a base class
           3
           4// constructor
           5public base(){
           6System.out.println("base class construct");
           7}

           8// perform
           9public void perform(){
          10System.out.println("base class perform");
          11}

          12// destructor
          13public void finalize(){
          14System.out.println("base class destruct");
          15}

          16}

          17
          18
          19class subbase extends base{// derive from base
          20
          21// constructor
          22public subbase(){
          23System.out.println("sub class construct");
          24}

          25// perform
          26public void perform(){
          27System.out.println("sub class perform");
          28}

          29// destructor
          30public void finalize(){
          31System.out.println("sub class destruct");
          32}

          33}

          34
          35public class casting{// test casting class
          36// constructor
          37public casting(){
          38System.out.println("begin casting test");
          39}

          40
          41public static void main(String args[]){
          42base father = new base();
          43subbase son = new subbase();
          44
          45father.perform();
          46son.perform();
          47
          48father = (base)son; // <1>
          49father.perform();
          50
          51son = (subbase)father; // <2>
          52son.perform();
          53
          54father = (base)((subbase)father); // <3>
          55father.perform();
          56}

          57}

          58
          59// codes end
          60
          Today ,when i go for a interview ,the project manager asked me this question !
          Acturally ,It's just relate to the knowledge of reference &&  object !
          Be carefull ,Nothing !

          posted @ 2008-05-25 19:40 devliu 閱讀(109) | 評論 (0)編輯 收藏

          <2008年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          導(dǎo)航

          統(tǒng)計

          常用鏈接

          留言簿(1)

          隨筆檔案

          搜索

          最新評論

          主站蜘蛛池模板: 石家庄市| 河北省| 平度市| 海安县| 余江县| 勃利县| 周至县| 秦皇岛市| 丹凤县| 沭阳县| 青铜峡市| 故城县| 冷水江市| 溆浦县| 盐山县| 孟州市| 鲁甸县| 宣武区| 湟源县| 万源市| 湾仔区| 车险| 璧山县| 婺源县| 宁晋县| 乌鲁木齐市| 塔河县| 永胜县| 虎林市| 临城县| 团风县| 行唐县| 古田县| 泸州市| 汾阳市| 临朐县| 柳州市| 温泉县| 泾源县| 陇西县| 阿图什市|