Does Java support Mulitiple Inheritance?

后端 未结 5 1803
半阙折子戏
半阙折子戏 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:48

    From the Java fact that all class in Java have a parent class as Object

    Actually no, that's not true. Object is only the default parent class. If you explicitly specify a parent, as in your example (A extends B), then the class you're defining no longer has Object as an immediate parent.

    However, the fact that Object is the default means that it's impossible to create a class (except for Object itself) without a superclass. Since every class must have a superclass, every class has to have Object as an ancestor at some level.

提交回复
热议问题