How can multiple inheritance solve the problem of Deadly Diamond of Death
posted 15 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hi
Java does not support multiple inheritance , because of the Deadly Diamond of Death problem . however the problem can be solved by multiple inheritance in Interfaces . Can anyone explain ?
Java does not support multiple inheritance , because of the Deadly Diamond of Death problem . however the problem can be solved by multiple inheritance in Interfaces . Can anyone explain ?
posted 15 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
The diamond problem can occur using interfaces. An example:
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
posted 15 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Java allows multiple inheritance with interfaces but not with implementations.
This helps if two interfaces define the same method signature. It doesn't matter which interface defined the method if a class implements both. So there is no problem in resolving which code to call as it would be when two super classes would provide method implementations for methods with the same signature.
It doesn't help when methods in different interfaces are not compatible, i.e. have different return types or have generified types that lead to the same method signature after type erasure.
Oh, and obviously it doesn't allow you to pull in code from different base implementations.
This helps if two interfaces define the same method signature. It doesn't matter which interface defined the method if a class implements both. So there is no problem in resolving which code to call as it would be when two super classes would provide method implementations for methods with the same signature.
It doesn't help when methods in different interfaces are not compatible, i.e. have different return types or have generified types that lead to the same method signature after type erasure.
Oh, and obviously it doesn't allow you to pull in code from different base implementations.
posted 15 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Why Multiple Inheritance is not supported in Java Classes?...
What i think is...
Multiple Inheritance is nothing but different characteristics of two or more parent classes is inherited by Children classes. Same characteristic from two or more parent class would take into Children class to dilemma of what class to select to inherit that characteristic.
Since all Java classes is designed in such a way of extending "Object" class... So, Multiple Inheritance property falls short due to this design... So Multiple Inheritance property is brought into Java in form of Interfaces...
What i think is...
Multiple Inheritance is nothing but different characteristics of two or more parent classes is inherited by Children classes. Same characteristic from two or more parent class would take into Children class to dilemma of what class to select to inherit that characteristic.
Since all Java classes is designed in such a way of extending "Object" class... So, Multiple Inheritance property falls short due to this design... So Multiple Inheritance property is brought into Java in form of Interfaces...
SCJP 6 [SCJP - Old is Gold]
posted 15 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Thanks Hauke i can understand it now completely.
posted 15 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
No, Java does not allow multiple inheritance at all. Using Object does not constitute multiple inheritance, only a longer inheritance "tree". An interface extending several other interfaces does not constitute multiple inheritance.
Implementing multiple interfaces does not constitute multiple inheritance either, but it allows one to mimic it.
Implementing multiple interfaces does not constitute multiple inheritance either, but it allows one to mimic it.
Hauke Ingmar Schmidt
Rancher
Posts: 436
2
posted 15 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
The JLS itself speaks of multiple inheritance for interfaces: JLS - 9. Interfaces.
Campbell Ritchie
Marshal
Posts: 81619
593
posted 13 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
If you look at the most recent edition of the JLS, however, and use ctrl-F “multiple inheritance”, the phrase only comes up once as something prohibited.Hauke Ingmar Schmidt wrote:The JLS itself speaks of multiple inheritance for interfaces: JLS - 9. Interfaces.
Hauke Ingmar Schmidt
Rancher
Posts: 436
2
posted 13 years ago
Because they use bracketsnow: "This (multiple) interface inheritance allows objects to support (multiple) common behaviors without sharing any implementation." http://docs.oracle.com/javase/specs/jls/se7/html/jls-9.html
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Campbell Ritchie wrote:
If you look at the most recent edition of the JLS, however, and use ctrl-F “multiple inheritance”, the phrase only comes up once as something prohibited.Hauke Ingmar Schmidt wrote:The JLS itself speaks of multiple inheritance for interfaces: JLS - 9. Interfaces.
Because they use brackets
| I want my playground back. Here, I'll give you this tiny ad for it: Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |










