我有
public class D extends B
{
public void method() {}
}
public class B
{
public void method() {}
public void anotherMethod() { method(); }
}
在上面,如果你持有 D 的一个实例,比如 d,d.anotherMethod() 会导致调用 D.method。
Java 中是否有从 anotherMethod() 内部调用 B.method() 的语法?
最佳答案
不,没有。派生类必须包含对 super.method()
的调用。
如果 B
想要防止子类覆盖 method()
,它应该将 method()
声明为 final
.
关于java - 调用未覆盖方法的语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3533772/