Muliple inheritance
posted 19 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hi friends,
Why multiple inheritance is not supported by JAVA?
thanks
Shubha
Why multiple inheritance is not supported by JAVA?
thanks
Shubha
Shubhada
posted 19 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Because...they decided not to.
I guess it's less confusing this way...
I guess it's less confusing this way...
posted 19 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Moving to Java In General (Beginner) forum.. This isnt covered in the SCJP exam.
Mark
Mark
posted 19 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
posted 19 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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.
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.
posted 19 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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.
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.
Regards,
vignesh
| Too many men are afraid of being fools - Henry Ford. Foolish tiny ad: Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |








