• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why java do not have multiple inheritance?

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

I know that Java implemented single inheritance to make the inheritance simple and robust. It can make use of interfaces to have multiple inheritance. But why it can not inherit more than two classes like C++ ? C++ has given solution for avoiding ambiguity of which method to call if the same method exist in both super classes, then why java don't use that?

Is there any other reason apart from this?

- Vivian
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because multiple inheritance is complicated and not needed. One problem that multiple inheritance introduces into a language is the diamond problem. In C++ this was solved by giving you both options: the default is to have separate instances of the contained superclass, and with virtual inheritance you can have a shared instance of the contained superclass.

In practice, multiple inheritance is never really necessary - I haven't felt the need to use it in the 8 years that I'm developing software in Java.

So the Java language designers chose to not make Java unnecessarily complex and left it out.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It also bears pointing out that in the early 90's, when Java was being developed, C++ compilers that correctly dealt with MI in all cases were rare if not nonexistent. Visual C++ was horribly broken, g++ wasn't much better. It's really far more complex than it appears on the surface, and getting it right is hard.
 
Warning! Way too comfortable! Do not sit! Try reading this tiny ad instead:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic