Search code examples
javainterfacemultiple-inheritance

Can a normal Class implement multiple interfaces?


I know that multiple inheritances between Interfaces is possible, e.g.:

public interface C extends A,B {...} //Where A, B and C are Interfaces

But is it possible to have a regular Class inherit from multiple Interfaces like this:

public class A implements C,D {...} //Where A is a Class and C and D are interfaces

Solution

  • A Java class can only extend one parent class. Multiple inheritance (extends) is not allowed. Interfaces are not classes, however, and a class can implement more than one interface.

    The parent interfaces are declared in a comma-separated list, after the implements keyword.

    In conclusion, yes, it is possible to do:

    public class A implements C,D {...}