abstract class SuperParent
{
public abstract void Show();
public void Display()
{
System.out.println("HI............I m ur grandpa and in Display()");
}
}
abstract class Parent extends SuperParent
{
public abstract void Detail();
public void Show()
{
System.out.println("implemented abstract Show()method of Superparent in parent thru super");
}
public void Display()
{
System.out.println("Override display() method of Superparent in parent thru super");
}
}
public class Child extends Parent
{
Child()
{
super.Show();
super.Display();
}
public void Show()
{
System.out.println("Override show() method of parent in Child");
}
public void Detail()
{
System.out.println("implemented abstract Detail()method of parent ");
}
public void Display()
{
System.out.println("Override display() method of Superparent and Parent in child ");
}
public static void main(String[] args) {
Child c1= new Child();
c1.Show();
c1.Display();
Parent p1=new Child();
p1.Detail();
p1.Display();
p1.Show();
}
}
我创建了一个抽象类superparent,其中包含一个抽象方法show()和一个具体方法Display()。现在我们创建一个Parent类extends superparent,其中包含一个抽象方法detail()和具体方法display(),它覆盖了superparent并实现show()方法,它是superparent中的抽象,现在我创建一个子类extends Parent,使用实现方法Detail(),它在Parent中是抽象的,覆盖display()方法,在父级和superparent中,并且覆盖show(),是在父母。现在我创建一个子实例并运行所有方法,它调用所有子方法,罚款。如果我们想运行父方法然后我们在构造函数中使用super.parent方法,运行正常。但我如何运行superparent方法display()来自儿童班。
答案 0 :(得分:1)
Java语言不支持。
您必须从SuperParent.show()
致电Parent
并从Child
调用此代码:
abstract class Parent extends SuperParent {
...
public void superParentShow() {
super.Show();
}
}
然后致电
super.superParentShow()
来自Child
。
相关问题: