Java最佳实践:重新声明继承的接口?

时间:2018-01-29 05:02:01

标签: java

我知道当一个类扩展另一个类时,它将继承它已实现的所有接口。就最佳实践而言,在子类中再次声明是否有意义?

public interface LeggedCreature {
    public int getLegCount();
}

public abstract class Animal implements LeggedCreature {
    ...
}

public class Dog extends Animal {
    @Override public int getLegCount() { return 4; }
}

public class MutatedDog extends Dog {
    @Override public int getLegCount() { return 6; }
}

这是否更有意义,或者下面的版本是否更有意义?

public class MutatedDog extends Dog implements LeggedCreature {
    @Override public int getLegCount() { return 6; }
}

0 个答案:

没有答案
相关问题