Search code examples
javainheritanceinterface-implementation

Does a class which is extending an abstract class still has to implement the interface that abstract class is implementing?: java


public abstract class ClassA implements ClassB{
}



public class ClassC extends ClassA implements ClassB{
}

Since class "ClassC" is extending class "ClassA", does "ClassC" still has to implement "ClassB"? Or "ClassB" is automatically implemented for class "ClassC"?


Solution

  • Assuming ClassA is not abstract and fully implements ClassB, then ClassC inherits ClassA's implementation and does not need to re-implement anything from ClassB unless it wants to override the behavior.

    It also does not need to specify implements ClassB. The following example is valid:

    public static interface I { }
    public static class A implements I { }
    public static class B extends A { }
    
    public static void main(String[] args) {
        I b = new B();
    }