如:
class GrandPa
{
void Method()
{
System.out.println("Hello, I am GrandPa!");
}
}
class Father extends GrandPa
{
void Method()
{
System.out.println("Hello, I am Father!");
}
}
class Son extends Father
{
void Method()
{
// 如何调用GrandPa的Method? super.Method();
System.out.println("And Son is followed!");
}
}
class GrandPa
{
void Method()
{
System.out.println("Hello, I am GrandPa!");
}
}
class Father extends GrandPa
{
void Method()
{
System.out.println("Hello, I am Father!");
}
}
class Son extends Father
{
void Method()
{
// 如何调用GrandPa的Method? super.Method();
System.out.println("And Son is followed!");
}
}
还有什么更好的方法?因为如果GrandPa是抽象类的话,这招就不灵了。
class Father extends GrandPa
{
void Method()
{
System.out.println("Hello, I am Father!");
}
void methodAgain()
{
super.Method();
System.out.println("Hello, I am Father!");
}
}so, in the sub-sub-class you will invoke like this: super.methodAgain();
System.out.println("And Son is followed!");it will never, ever affect the father class nor the top class.i thing u get it, huh?my regards
{
static void Method()
{
System.out.println("Hello, I am GrandPa!");
}
}
class Father extends GrandPa
{
static void Method()
{
System.out.println("Hello, I am Father!");
}
}
class Son extends Father
{
static void Method()
{
GrandPa.Method();// 这样可以调用GrandPa的Method Father.Method();
System.out.println("And Son is followed!");
}
}
很好的解释
因为是多态,你只能知道你的父类,根本不应该和父类的父类有任何牵连.我要调用Object的toString()方法怎么办?
有点自相毛度