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 1:
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 {...}
Solution 2:
public class A implements C,D {...} valid
this is the way to implement multiple inheritence in java
Solution 3:
In a word - yes.
Actually, many classes in the JDK implement multiple interfaces. E.g., ArrayList
implements List
, RandomAccess
, Cloneable
, and Serializable
.