您的位置:首页 > 编程语言 > Java开发

Java - Why multiple inheritances are not supported in Java

2015-07-01 11:15 495 查看
http://javarevisited.blogspot.de/2011/07/why-multiple-inheritances-are-not.html

Sometimes I can't open this page without proper proxy, so I have to copy the content here.

1) First reason is ambiguity around Diamond problem. Consider a class A has foo() method and then B and C derived from A and has their own foo() implementation and now class D derive from B and C using multiple inheritance. And
if we refer just foo(), compiler will not be able to decide which foo() it should invoke. This is also called Diamond problem because structure on this inheritance scenario is similar to 4 edge diamond, see below

A foo()

/ \

/ \

foo() B C foo()

\ /

\ /

D

foo()

2) Second and more convincing reason to me is that multiple inheritances does complicate the design and creates problem during casting, constructor chaining etc. 没有多少场景需要多重继承。 可以通过实现Interface来间接实现多重继承。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: