说我有一个界面和一个类:
public static interface Businessman { public void workHard(); }
public static class CTO implements Businessman {}
我应该为CTO创建一个不再是抽象的父母?
答案 0 :(得分:0)
假设您不希望编译器抱怨CTO
不是抽象的,您可以对Businessman
进行CTO
的默认(“不执行任何操作”)实现。// DefaultBusinessman.java
public class DefaultBusinessman implements Businessman {
@Override
public void workHard() {
}
}
// CTO.java
public class CTO extends DefaultBusinessman {
// CTO does no longer need to be abstract, as the implementation of doWork is provided
// through inheritance
}
继承:
{{1}}
答案 1 :(得分:0)
您可以将CTO创建为抽象,而不必实现商人
public abstract class CTO implements Businessman {}
public class specificCTO extends CTO {
@Override
public void workHard() {
}
}