class father{ void method(){
System.out.println("father.amethod()");
}}
class son extends father{
int n=6;
void method(){
System.out.println("测试覆盖:son.amethod()");
}
void fun(double d){
System.out.println("d="+d);
}
}
public class TestD extends son{
String m = "fgdsfgfdg";
void shuchu(){
//System.out.println("测试super"+super.fun(3.14));
System.out.println("测试this:"+this.m);
System.out.println("测试super:"+super.n);
}
void fun(int i){
System.out.println("测试重载:i="+i);
}
public static void main(String []args){
father f1 = new father();
father f2 = new son();
f1.method();
f2.method();//多态,覆盖
TestD td = new TestD();
td.shuchu();
son s = new TestD();
//TestD s = new TestD();
s.fun(454);
}
}
System.out.println("father.amethod()");
}}
class son extends father{
int n=6;
void method(){
System.out.println("测试覆盖:son.amethod()");
}
void fun(double d){
System.out.println("d="+d);
}
}
public class TestD extends son{
String m = "fgdsfgfdg";
void shuchu(){
//System.out.println("测试super"+super.fun(3.14));
System.out.println("测试this:"+this.m);
System.out.println("测试super:"+super.n);
}
void fun(int i){
System.out.println("测试重载:i="+i);
}
public static void main(String []args){
father f1 = new father();
father f2 = new son();
f1.method();
f2.method();//多态,覆盖
TestD td = new TestD();
td.shuchu();
son s = new TestD();
//TestD s = new TestD();
s.fun(454);
}
}
void fun(int i){
System.out.println("测试重载:i="+i);
}
与父类
void fun(double d){
System.out.println("d="+d);
}
是不同的(参数类型不一样)
所以父类的方法没有被覆写
s是son类型的
所以自然调用父类的fun()方法