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

Why Java didnt have mulitple inheritence via extending class

 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was just jumbled upon one question and to be curious, I would like to know, why Java didn't allow multiple inheritence via extending classes and why it did implement it via interface technique?

Thanks in advance.
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Extending multiple classes was primarily left out in order to keep Java "simple." The main problem which programmers could encounter with being able to extend multiple classes is the Diamond Problem (which I prefer to call the Dastardly Diamond of Death) When extending multiple classes it creates a serious possibility of ambiguity in your method calls/classes. The reason why multiple interfaces are allowed to be implemented is that you must override all methods provided by the interfaces you are implementing. While you can still have odd naming problems with multiple interfaces the forced override of all methods in the implementing class helps to limit all the pitfalls of extending multiple classes.

There was an old entertaining article about interfaces and why Java developers decided to go the route the did, I will edit my post if I come across it again.
 
author
Posts: 23942
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Also... please search the forums, as this question comes up often.

Henry
 
See where your hand is? Not there. It's next to this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic