????java??????
??????ν????????????????????????????????ж????????????????????????????????????????????????java???????е?????????????????????μ???????
class Father {
public void method(){
System.out.println("This is Father's method");
}
}
class Son1 extends Father{
public void method(){
System.out.println("This is Son1's method");
}
}
class Son2 extends Father{
public void method(){
System.out.println("This is Son2's method");
}
}
public class Test {
public static void main(String[] args){
Father s1 = new Son1();
s1.method();
Father s2 = new Son2();
s2.method();
}
}
???????н?????£?
????This is Son1′s method
????This is Son2′s method
??????????н??????????????????????????????Father???????????????????????????????????Son1??Son2?????????????????????java?????У?????е????????????????????????????????????????????????????????????????????????
????java??????
????????????????????????????????????????????????????java?У????????????????????????????????????????????????????????????????????????????????????′???
class Father {}
class Son1 extends Father{}
class Son2 extends Father{}
class Execute {
public void method(Father father){
System.out.println("This is Father's method");
}
public void method(Son1 son){
System.out.println("This is Son1's method");
}
public void method(Son2 son){
System.out.println("This is Son2's method");
}
}
public class Test {
public static void main(String[] args){
Father father = new Father();
Father s1 = new Son1();
Father s2 = new Son2();
Execute exe = new Execute();
exe.method(father);
exe.method(s1);
exe.method(s2);
}
}