1

我有一个抽象类:

public abstract class Parent{

    public void cook(){
        DoSomething(); //call abstract method
    }

    protected abstract void DoSomething();

}

我有一个具体的类来实现上述抽象类:

public Child extends Parent{
   private Toy toy;

   public void initToy(){
      toy.setOnPlayListener(new OnPlayListener() {
            @Override
            public void onPlay() {
                //How to call parent class cook() method here?
            }
        });
   }

   @Override
   public void DoSomething(){...}
}

我想在类中的 override函数中调用当前 Child 实例下的类的cook()方法。怎么做?ParentonPlay()OnPlayListener()Child

========更新=======

感谢您的回答,现在我想澄清一下,是Child.super.cook()Child.this.cook()同一件事吗??

4

1 回答 1

3

您需要获取封闭类实例的超类

@Override
public void onPlay() {
    Child.super.cook();
}
于 2013-11-13T16:15:21.607 回答