Multiple Inheritance in java

前端 未结 8 1424
無奈伤痛
無奈伤痛 2020-11-27 21:27

Java is not allowing inheritance from multiple classes (still it allows inheritance from multiple interfaces.), I know it is very much inline with classic diamond problem. B

8条回答
  •  Happy的楠姐
    2020-11-27 21:39

    It is true that Java did not use to support multiple inheritance of implementation (just of type i.e. interface). That was a design decision.

    However, since Java 8, it supports multiple inheritance using default methods. See http://docs.oracle.com/javase/tutorial/java/IandI/multipleinheritance.html:

    Multiple inheritance of implementation is the ability to inherit method definitions from multiple classes. Problems arise with this type of multiple inheritance, such as name conflicts and ambiguity. ... Default methods introduce one form of multiple inheritance of implementation.

提交回复
热议问题