我有一个抽象类:
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(){...}
}
我想在cook()
的覆盖Parent
函数中调用当前子实例下onPlay()
类的OnPlayListener()
方法Child
1}}类。怎么做?
======更新=======
感谢您的回答,现在我想说清楚,Child.super.cook()
& Child.this.cook()
同样的事情?
答案 0 :(得分:3)
您需要获取封闭类实例的超类
@Override
public void onPlay() {
Child.super.cook();
}