Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why Java didnt have mulitple inheritence via extending class

 
MaheshS Kumbhar
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • 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.
 
Bobby Smallman
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • 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.
 
Henry Wong
author
Marshal
Pie
Posts: 21194
81
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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

Henry
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic