Love Java,Love China!

          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 on 2008-05-25 19:40 devliu 閱讀(109) 評論(0)  編輯  收藏


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


          網(wǎng)站導(dǎo)航:
           
          <2008年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          導(dǎo)航

          統(tǒng)計

          常用鏈接

          留言簿(1)

          隨筆檔案

          搜索

          最新評論

          主站蜘蛛池模板: 弋阳县| 儋州市| 上思县| 阳东县| 赣州市| 手机| 大竹县| 巴林左旗| 鄂尔多斯市| 井陉县| 丹棱县| 金沙县| 眉山市| 江西省| 五指山市| 临高县| 祁门县| 资溪县| 当涂县| 呼和浩特市| 凌海市| 天镇县| 怀集县| 永嘉县| 拉萨市| 晴隆县| 容城县| 井冈山市| 和平区| 祁连县| 黑河市| 黔西县| 沙田区| 新乡县| 盐亭县| 炉霍县| 台南市| 汉阴县| 民丰县| 高台县| 武胜县|