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 閱讀(110) 評論(0)  編輯  收藏


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


          網站導航:
           
          <2008年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          導航

          統計

          常用鏈接

          留言簿(1)

          隨筆檔案

          搜索

          最新評論

          主站蜘蛛池模板: 长兴县| 渑池县| 南郑县| 河曲县| 读书| 苍梧县| 彭水| 大石桥市| 德钦县| 宜兰市| 林甸县| 平陆县| 吴川市| 柳州市| 黑水县| 宝丰县| 崇仁县| 武强县| 长岭县| 静宁县| 亚东县| 子洲县| 惠东县| 五原县| 临夏县| 昌乐县| 定远县| 西贡区| 古田县| 阿拉尔市| 来凤县| 高唐县| 潼关县| 绩溪县| 平乐县| 天等县| 刚察县| 读书| 桓台县| 山东省| 德安县|