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)編輯 收藏

          僅列出標題  
          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          導航

          統計

          常用鏈接

          留言簿(1)

          隨筆檔案

          搜索

          最新評論

          主站蜘蛛池模板: 通化市| 灵武市| 四平市| 车致| 华池县| 西和县| 孟津县| 大兴区| 天长市| 大荔县| 东丽区| 五常市| 吴江市| 上杭县| 连江县| 郯城县| 青阳县| 清丰县| 信阳市| 宁都县| 镇赉县| 凌源市| 元氏县| 科技| 绿春县| 同德县| 江口县| 宁国市| 疏勒县| 淮滨县| 昂仁县| 唐河县| 青海省| 宁波市| 安顺市| 孝义市| 五莲县| 万州区| 阳高县| 云霄县| 青岛市|