This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

why java does not support Multiple Inheritance?

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi.
What is Multiple Inheritance .why java does not support ?

bye
sreedahr
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The designers of the language decided (correctly IMO) that multiple inheritance is more trouble than it's worth.
Most uses of it in C++ are due to poor design choices or the lack of interfaces, so having interfaces instead of multiple inheritance makes for better code.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is not a Servlet question. I'll move it to the Java in General (beginner) forum for you.
Dave
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

Multiple inheritance is a way to inherit some properties , methods from the different classes(many parent class ).

i think, Interface concept is lot easy to understand write and implement .It does the same as multiple inheritance , but in a better way.
GOOG LUCK.
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sreedhar,

C++ supports multiple inheritance, in sense, A class canbe derived from more than one base class. The problem that the c++ programmers face with multiple inheritance is ambiguity in inherited members, you can understand that if you consider the famous rhombus problem.
ClassA //m1() (protected)
|
-------------
| |
ClassB ClassC
| |
--------------
|
ClassD //gets m1 from the path A,B and A,C
Here, class A has a protected member m1, the classes B and C are derived from A and hence will inherit m1(), assume the method is not overridden in the child classes. Now, D is derived from both B and C, D will have two copies of m1 and hence arises ambiguity. C++ tries to solve this problem by using virtual inheritance, but again, this is not a 100% solution.
Java does support multiple inheritance, but, not directly.
In java, a class can implement, more than one interface. Assume two interface have identical method declarations, it is enough if we define the method only once in the implementing class. Here, there is no ambiguity problems, because the methods' functionality is not defined in the interfaces.
Consider this code,

How will you give different implementations for different interfaces??? In sense, if the method display() is called from I1 reference it should print "From I1" and from I2 reference should print "From I2"
Thanks,
Uma...
 
reply
    Bookmark Topic Watch Topic
  • New Topic