要么将您的方法设为静态(baadddddd),要么更改您的设计。
确实,为子类提供默认行为是没有意义的,该子类被定义为适合于所关注的方法。
由于您的
foo()方法似乎有所不同,因此您可以实施以下策略模式:
interface BarProcess{ void foo();}public class DefaultBarProcess implements BarProcess{ void foo() { System.out.println("Foo from A"); }}public class AnotherBarProcess implements BarProcess{ void foo() { System.out.println("Foo from B"); }}class A { private BarProcess barProcess; public A(Bar barProcess){ this.barProcess = barProcess; } void bar() { barProcess.foo(); }}class B extends A { //deprecated! No need to exist}


