• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

How can multiple inheritance solve the problem of Deadly Diamond of Death

 
Ranch Hand
Posts: 198
Oracle Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The diamond problem can occur using interfaces. An example:

 
Rancher
Posts: 436
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 247
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
ragi singh
Ranch Hand
Posts: 198
Oracle Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Hauke i can understand it now completely.
 
Marshal
Posts: 75663
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Hauke Ingmar Schmidt
Rancher
Posts: 436
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The JLS itself speaks of multiple inheritance for interfaces: JLS - 9. Interfaces.
 
Campbell Ritchie
Marshal
Posts: 75663
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hauke Ingmar Schmidt wrote:The JLS itself speaks of multiple inheritance for interfaces: JLS - 9. Interfaces.

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
Rancher
Posts: 436
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

Hauke Ingmar Schmidt wrote:The JLS itself speaks of multiple inheritance for interfaces: JLS - 9. Interfaces.

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.



Because they use brackets now: "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
 
It's hard to fight evil. The little things, like a nice sandwich, really helps. Right tiny ad?
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic