class Grandfather
{
public void print()
{
System.out.println("Grandfather") ;
}
};
class Father extends Grandfather
{
public void print()
{
System.out.println("father") ;
}
public void funFather()
{
this.print() ;
super.print() ;
}
};
class Child extends Father{ // 定义继承关系
public void print()
{
System.out.println("child") ;
}
public void funChild()//避免覆写
{
this.print() ;
super.print() ;
}
};
public class test3{
public static void main(String args[])
{
Child s = new Child() ;
s.funFather() ;//此处通过继承调用父类函数中的 this.print与super.print
s.funChild();//此处直接调用子类类 this.print与super.print
}
};
输出为
child
Grandfather
child
father
为什么第一个输出是child呢???而不是father?? |
|