shrumsowen11
shrumsowen11

Reputation: 57

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"?

Upvotes: 0

Views: 52

Answers (2)

Jim Garrison
Jim Garrison

Reputation: 86764

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();
}

Upvotes: 1

You dont need do implement again it is already implemented by the Product Class, i've created an example to show you

enter image description here

I created the method just to show you how it would work

enter image description here

enter image description here

enter image description here

If you implement the interface into the super class all the childs will have the Interface methods! Hope it helps :)

Upvotes: 0

Related Questions