數(shù)據(jù)加載中……
          繼承

          public class Animal

          {

          ????int height;

          ????int weight;

          ????void animal()

          ????{

          ????????System.out.println("Animal constract");

          ????}

          ????void eat()

          ????{

          ????????System.out.println("Animal eat");

          ????}

          ????void sleep()

          ????{

          ????????System.out.println("Animal sleep");

          ????}

          ????void breathe()

          ????{

          ????????System.out.println("Animal breathe");

          ????}

          }

          /*

          * 理解繼承是理解面向?qū)ο蟪绦蛟O(shè)計(jì)的關(guān)鍵

          * 在java中,通過關(guān)鍵字extends繼承一個(gè)已有的類,被繼承的類稱為父類(超類,基類),新的類稱為子類(派生類)。

          * * 在java中,不允許多繼承

          */

          class Fish extends Animal

          {

          ????void fish()

          ????{

          ????????

          ????????System.out.println("fish constract");

          ????}

          ????void breathe()

          ????{

          ????????//super.breathe();

          ????????//super.height=40;

          ????????System.out.println("fish boo");

          ????}

          }

          class Integration

          {

          ????public static void main(String[]args)

          ????{

          ????????//Animal an=new Animal();

          ????????Fish fh=new Fish();

          ????????//an.breathe();

          ????????//fh.height=30;

          ????????fh.breathe();

          ????????

          ????}

          }

          /*

          *在子類當(dāng)中定義一個(gè)與父類同名,返回類型,參數(shù)類型均一致的方法,稱為方法的覆蓋

          *方法的覆蓋發(fā)生在子類和父類之間。

          *調(diào)用父類的方法使用super

          */

          /*特殊變量super,提供了父類的訪問

          * 可以使用super訪問被父類被子類隱藏的變量或覆蓋的方法

          * 每個(gè)子類構(gòu)造方法的第一句,都是隱藏的調(diào)用super(),如果父類沒有這種形式的構(gòu)造函數(shù),那么在編譯器中就會(huì)報(bào)錯(cuò)。

          *

          *

          *

          */

          posted on 2008-03-20 11:58 rick 閱讀(197) 評論(0)  編輯  收藏


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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 诸城市| 育儿| 旺苍县| 公安县| 诸城市| 康平县| 徐闻县| 元朗区| 大悟县| 宣汉县| 双桥区| 湾仔区| 鄯善县| 阜新市| 南靖县| 寻乌县| 府谷县| 巨鹿县| 长武县| 东莞市| 清丰县| 冷水江市| 莱西市| 永吉县| 锦屏县| 开化县| 白水县| 佛冈县| 乌鲁木齐县| 建宁县| 久治县| 缙云县| 宁明县| 泾阳县| 伊金霍洛旗| 大关县| 梁河县| 嘉义市| 青铜峡市| 延庆县| 新平|