BloveSaga

          在希臘帕爾納斯山南坡上,有一個馳名世界的戴爾波伊神托所,在它的入口處的巨石上赫然銹刻著這樣幾個大字: 認識你自己!

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            34 隨筆 :: 12 文章 :: 122 評論 :: 0 Trackbacks

          ?通過覆蓋父類的方法來實現(xiàn),在運行時根據(jù)傳遞對象的引用,來調(diào)用相應的方法.
          code:
          class Animal
          {
          ?int height,weight;
          ?Animal()
          ?{
          ??System.out.println("Animal construct");
          ?}
          ?void eat()
          ?{
          ??System.out.println("Animal eat!");
          ?}
          ?void sleep()
          ?{
          ??System.out.println("Animal sleep!");
          ?}
          ?void breathe()
          ?{
          ??System.out.println("Animal breathe!");
          ?}
          }

          class Fish extends Animal
          {
          ?Fish()
          ?{
          ??System.out.println("Fish construct");
          ?}
          ?void breathe()? //override method breathe()
          ?{
          ??System.out.println("Fish bubble");
          ?}
          }
          class DoMain
          {
          ?static void fn(Animal an)
          ?{
          ??an.breathe();
          ?}
          ?public static void main(String[] args)
          ?{
          ??//Animal an=new Animal();
          ??Fish fh=new Fish();
          ??Animal an;
          ??an=fh;
          ??DoMain.fn(an);
          ?}
          }

          posted on 2006-06-04 11:40 藍色Saga 閱讀(160) 評論(0)  編輯  收藏 所屬分類: Basic Study for JAVA
          主站蜘蛛池模板: 汝阳县| 迁安市| 长顺县| 海林市| 贵港市| 揭西县| 泰顺县| 汉中市| 商丘市| 金沙县| 基隆市| 揭西县| 越西县| 昌都县| 车险| 阿鲁科尔沁旗| 德格县| 荔浦县| 民权县| 宣恩县| 鸡东县| 卢龙县| 特克斯县| 德钦县| 邵阳县| 如东县| 安泽县| 志丹县| 桦川县| 海兴县| 竹溪县| 许昌市| 滨海县| 通辽市| 类乌齐县| 广德县| 正宁县| 天峨县| 辽宁省| 巴南区| 韩城市|