If a method in the base class can have an override, and the derived class has provided one, there is no way to force a call to the method of the base class.
If the base class needs to call the functionality in the base class, it can put it into a separate method, and declare it final
. Then it could make a decision between its own implementation and the derived implementation like this:
public class Base {
public Base() { }
public void methodA() {
System.out.println("Base: methodA");
// Call the derived method
methodB();
// Call the base method
methodB_impl();
}
public final void methodB_impl() {
System.out.println("Base: methodB");
}
public void methodB() {
methodB_impl();
}
}