• 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
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Muliple inheritance

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends,

Why multiple inheritance is not supported by JAVA?

thanks
Shubha
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because...they decided not to.

I guess it's less confusing this way...
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to Java In General (Beginner) forum.. This isnt covered in the SCJP exam.

Mark
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Java designers copied a lot of things from C and C++ to make the transition from those languages easy. But they also had a list of things that made C/C++ too hard or error prone that they deliberately left out of Java. Multiple inheritance was in the cut list.
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Although the responses are correct, there is more to the story than that. In the early 1990s, before Java was released, C++ was the dominant OO language for development, and it went through some growing pains. One of the problems compilers ran into was how to properly represent multiple inheritance that a)worked, and b)was relatively efficient. Multiple inheritance, it turned out, wasn't as big a problem inherently as "common" multiple inheritance, in which the two superclasses share a third common class. This resulted in a relationship called, believe it or not, the "diamond of death", because the class diagram for such a relationship formed a diamond, with the "common" base class at the top of the diamond.

The developer of Java (James Gosling) decided to implement much of the functionality of multiple inheritance via a new approach called an interface, eliminating much of the problem. However, it introduced a new problem...since interfaces don't have any code (only method declarations), what do you do if you need to "add" code from two different existing classes? In C++ it's easy...you just inherit from them. In Java, you have to jump through a few more hoops, but it's still possible to do.

In my experience, good design usually mitigates or eliminates the need for multiple inheritance. But every so often a problem arises for which multiple inheritance would actually make more sense that single inheritance.
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ya wat tom defind is absolutely right.. but the ultimate aim is to avoid name collision..

jus assume if java has multiple inheritance..



this is wat the problem with multiple inheritance. and as well u cannot force the java programmers to define different names for the methods. so avoid that too this is being handled. and in interfaces you are supposed to override all the methods. and even in interface also this happens if there are two mtd with same name and overriden..but the thing is if u have same method name in two interfaces then when u override one method then you will be able to define the body to only one of those methods. becoz two methods cant have the same name.so obviously you can define only one method of that name. and the implemented method ie. the overriden method will be called.when u create an object and call it.

i hope the explanation is far clear.
 
And inside of my fortune cookie was this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic