将父级添加到抽象类,使其不再是抽象的

时间:2014-06-24 13:56:07

标签: java

说我有一个界面和一个类:

    public static interface Businessman { public void workHard(); }

    public static class CTO implements Businessman {}

我应该为CTO创建一个不再是抽象的父母?

2 个答案:

答案 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() {
         }

     }