隨筆 - 72  文章 - 28  trackbacks - 0
          <2007年3月>
          25262728123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          常用鏈接

          留言簿(4)

          隨筆分類(66)

          隨筆檔案(72)

          文章檔案(19)

          收藏夾

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          1、重載是在一個類里一系列參數(shù)不同名字相同的方法.
                方法簽名由方法名稱和一個參數(shù)列表(方法的參數(shù)的順序和類型)組成。只要簽名不同,就可以在一種類型內(nèi)定義具有相同名稱的多種方法。當定義兩種或多種具有相同名稱的方法時,就稱作重載。
          2、重寫是繼承后重新實現(xiàn)父類的方法.派生類型可以重寫繼承的虛方法
          3、繼承是子類獲得父類的成員
          4、多態(tài)則是父類使用子類的方法

          下面給出一個例子:
          一個父類:test_father,一個子類:test_sub,來說明這幾個概念的關系
          test_father類:

          public class test_father {

           public  test_father() {
            System.out.println("father");//構造器
           }
           
           public void test_father() {
            System.out.println("father");//重載
           }
           public int test_father(int i) {
            System.out.println("fatherii"+i);
            return i;//重載
           }

          }

          test_sub類:
          public class test_sub extends test_father{//繼承

           public test_sub() {
            System.out.println("test_sub");//構造器
           }
           
           public void test_father() {
            System.out.println("sub");//重寫父類方法
           }
           public int test_father(int i) {
            System.out.println("subii"+i);
            
            return i;
           }

           /**
            * @param args
            */
           public static void main(String[] args) {
            // TODO Auto-generated method stub
            test_father fa=new test_sub();//多態(tài)
            fa.test_father();
            fa.test_father(3);
           }

          }

          輸出結果:
          father
          test_sub
          sub
          subii3


          posted on 2007-03-15 09:52 kelly 閱讀(669) 評論(0)  編輯  收藏 所屬分類: java
          主站蜘蛛池模板: 社旗县| 阳高县| 大同县| 班戈县| 吕梁市| 开原市| 安徽省| 镇康县| 海安县| 益阳市| 澄城县| 奎屯市| 乌拉特前旗| 象州县| 拜城县| 黄龙县| 天峨县| 札达县| 牟定县| 东兴市| 哈巴河县| 朝阳市| 淮北市| 营口市| 绥中县| 盐津县| 塔城市| 油尖旺区| 金沙县| 武川县| 丰城市| 南和县| 淳化县| 阜康市| 兴化市| 广东省| 皮山县| 行唐县| 延寿县| 潍坊市| 益阳市|