+ 2

Multiple inheritance does exist in Java!

However not for classes but for interfaces. I just came across a challenge where it asks me this and wanted to inform others that the answer that Java doesn't allow multiple inheritance is NOT CORRECT in all cases. As I said, multiple inheritance of classes is forbidden due to the "diamond problem" (http://www.journaldev.com/1775/multiple-inheritance-in-java), but it does support multiple inheritance (with interfaces though).

10th May 2017, 2:00 PM
Thanh Le
Thanh Le - avatar
3 ответов
+ 1
Thats not inheritance just extension of interfaces.
10th May 2017, 2:07 PM
Szabó Gábor
Szabó Gábor - avatar
0
@Szabó Gábor, according to the following definition, that IS inheritance: "In object-oriented programming, inheritance is when an object or class is based on another object (prototypal inheritance) or class (class-based inheritance), using the same implementation (inheriting from an object or class: inheriting behavior, programming by difference[1]) or specifying a new implementation to maintain the same behavior (realizing an interface). " Source: https://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming)
10th May 2017, 2:16 PM
Thanh Le
Thanh Le - avatar
0
@Tahn Le Interfaces doesn't contains implementations, just definitions. From Java 8 They can contain implementation by the default keyword, but then you can't extends interfaces what contains different implementations. So multiple inheritance doesn't exist in Java ! I made a code for demonstrate: https://code.sololearn.com/cpZyo9CZLzU5/#java Think interfaces methods like a set, if you extend more interface, the set can extend too, but if they contains a same method the set doesn't extend. Extend interfaces like make a bigger interface that contains all of the method what the others contain.
10th May 2017, 2:41 PM
Szabó Gábor
Szabó Gábor - avatar