經典例題分析

          ?

          ?1 class ?SuperClass
          ?2 {
          ?3 ???? void ?SuperClass() {System.out.print( " a " );} // 非構造函數,構造函數可聲明為public?SuperClass(){};
          ?4 ???? int ?a? = ? 8 ,b? = ? 6 ;}
          // 成員變量會被子類覆蓋繼承
          ?5 class ?SubClass? extends ?SuperClass
          ?6 {
          ?7 ???? void ?SuperClass() {System.out.print( " b " );} // 非構造函數,實現多態。
          ?8 // ????int?a=30,b=20;
          ?9 ???? /**
          10 ?????*? @return
          11 ????? */

          12 ???? int ?max() { return ?((a? > ?b) ? ?a:b);} }

          13 public ? class ?ABC? {
          14
          15 ???? /**
          16 ?????*? @param ?args
          17 ????? */

          18 ???? public ? static ? void ?main(String[]?args)? {
          19 ????SubClass?sb? = ? new ?SubClass();
          20 ????SubClass?mm? = ? new ?SubClass();
          21 ????mm.SuperClass();
          22 ????System.out.println(sb.max());
          23
          24 ????}

          25
          26 }
          分析
          1,多態在父類構造函數不能被繼承實現多態
          2,相同名字的父類的成員變量會被子類覆蓋,繼承。

          posted on 2007-01-15 11:17 youngturk 閱讀(334) 評論(0)  編輯  收藏


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


          網站導航:
           
          <2007年1月>
          31123456
          78910111213
          14151617181920
          21222324252627
          28293031123
          45678910

          導航

          統計

          公告

          this year :
          1 jQuery
          2 freemarker
          3 框架結構
          4 口語英語

          常用鏈接

          留言簿(6)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          相冊

          EJB學習

          Flex學習

          learn English

          oracle

          spring MVC web service

          SQL

          Struts

          生活保健

          解析文件

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 凤阳县| 隆安县| 巴里| 萨嘎县| 于田县| 东安县| 鄂尔多斯市| 张家口市| 安多县| 搜索| 新昌县| 汝城县| 乳山市| 孝感市| 华容县| 遂溪县| 肥西县| 谷城县| 响水县| 河西区| 宁南县| 济宁市| 密山市| 平安县| 淮阳县| 佛教| 疏附县| 政和县| 晋州市| 宁德市| 威远县| 南投市| 方正县| 淮安市| 乌兰浩特市| 扶风县| 全州县| 潞城市| 布拖县| 桃园市| 册亨县|