JAVA学習(10)継承(2)継承におけるメソッドの上書きとリロード

2017 ワード

関数と親が同じ名前の場合、パラメータが同じ場合は上書きされ、それ以外の場合は再ロードされます.
public class Test11A{

    public void somoke()
    {
        System.out.println("chouyan");
    }

}
public class Test11B extends Test11A{

    public void somoke()//     somoke  
    {
        System.out.println("bu chou yan");
    }
    public static void main(String[] args) {
        Test11B test  = new Test11B();
        test.somoke();
    }

}

再ロード:
public class Test11B extends Test11A{

    public void somoke(String  s)//    ,        
    {
        System.out.println(s);
    }
    public static void main(String[] args) {
        Test11B test  = new Test11B();
        test.somoke();
         test.somoke("hello");
    }

}