Why is there no multiple inheritance in Java, but implementing multiple interfaces is allowed?

后端 未结 18 1968
囚心锁ツ
囚心锁ツ 2020-11-22 14:55

Java doesn\'t allow multiple inheritance, but it allows implementing multiple interfaces. Why?

18条回答
  •  遥遥无期
    2020-11-22 15:36

    Because interfaces specify only what the class is doing, not how it is doing it.

    The problem with multiple inheritance is that two classes may define different ways of doing the same thing, and the subclass can't choose which one to pick.

提交回复
热议问题