Can a normal Class implement multiple interfaces?

后端 未结 8 1075
春和景丽
春和景丽 2021-01-31 01:34

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

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

8条回答
  •  死守一世寂寞
    2021-01-31 02:34

    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 {...}
    

提交回复
热议问题