Does Java support Mulitiple Inheritance?

后端 未结 5 1805
半阙折子戏
半阙折子戏 2021-01-25 15:03

From the Java fact that all class in Java have a parent class as Object. But the same Java says that it doesn\'t support multiple inheritance. But what this code me

5条回答
  •  无人及你
    2021-01-25 15:58

    No, this is single inheritance. A inherits from B, B inherits from Object.

    Multiple inheritance would be A extends from B and C, where B and C don't inherit from each other, which can cause the Diamond Problem:

    If B defines a method foo() and C also defines a method foo(), and I do this:

    new A().foo();
    

    Which foo() implementation will be used?

    This is a huge problem in many languages, so the Java designers decided not to allow multiple inheritance.

提交回复
热议问题