+ 2

Why multiple inheritance cannot be achieved in java? Why do we have to use interface to achieve multiple inheritance?

12th Aug 2017, 2:08 PM
Nivesh
Nivesh - avatar
2 ответов
+ 5
The initial Java design specification mentioned simplicity as one of its aims. Multiple Inheritance of classes would ruin that simplicity hence it was excluded. A simpler implementation of it could be achieved through interfaces.
17th Aug 2017, 9:57 PM
Garikai
Garikai - avatar
+ 1
In certain situation, multiple inheritance can cause 'The Deadly Diamond of Death', see http://wayback.archive.org/web/20051024230813/http://www.objectmentor.com/resources/articles/javacpp.pdf I think Java omited multiple inheritance to discourage the use and spare coders from possibly having to deal with this kind of bug that is hard to debug. This reduces the language flexibility, but encourage good programming practice.
18th Aug 2017, 4:24 PM
Ching Sian Wong
Ching Sian Wong - avatar