why java does not support multiple inheritance
Answers were Sorted based on User's Feedback
Answer / amod
In java single in-heritance is possible
where as mutiple in-heritance is not supported
we cannot extend multiple classes so its not possible for
multi[ple in heritance
Is This Answer Correct ? | 4 Yes | 4 No |
Answer / sreekanta paul
In C++ when a subclass inherits a superclass then the name of superclass is specified.But in java it is quite confusing from which superclass a method will be inherited by the subclass.Suppose wo classes B and C inherit from A, and class D inherits from both B and C. If a method in D calls a method defined in A (and does not override the method), and B and C have overridden that method differently, then from which class does it inherit: B, or C?
Thats why in java the concept of Interface came to solve this problem.
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / piyush patel
java is extended from C++ language.
in c++ we found Multiple inheritance make complexity or
confusion to called method.
example: suppose class A extends class B and class C
class B have method area(int i);
class C have method area(int i);
now if Class A call area(int i) then whose method will be
considered
contact me if any query about java
mob:9904449370
Is This Answer Correct ? | 2 Yes | 2 No |
Answer / farsim
Have a look at this ink you are not getting any better answer.
http://www.javaworld.com/javaworld/javaqa/2002-07/02-qa-0719-multinheritance.html
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / mahesh patil
Suppose consider a method aaa() which is in class Z.
Suppose a programmer ABC inherited the class Z to class X
and overrided the aaa().So this class will have the new
implementation of aaa().
Suppose a programmer DEF inherited the class Z to class Y
and overrided the aaa().So this class will have the new
implementation of aaa().
If Multiple Inheritance is permitted in java, then if the
new programmer inherited both the classes and he didn't done
any overriding of method aaa() then if he calls the aaa()
,the JVM will not know which method to call i.e., either the
method in class X or method in class Y.
Because of this inconsistencies,Multiple inheritance is not
permitted in java.
Is This Answer Correct ? | 1 Yes | 1 No |
Answer / krishna.tadi
multiple inheritance:
def:
The process of deriving a subclass from morethen 2 classes
java doesnot support multiple inheritance through the use of the class
Because the same method()names in the more than one class this introduces the ambiguity problem
So to avoid this in java interfaces are introduced in interface we have only method declarations and we have to implement that method not override
Is This Answer Correct ? | 1 Yes | 1 No |
Answer / professor pandit
Java does not support multiple inheritance of classes.
Answer as to its reasons on why it does not support MI runs
much deeper than what generally seems to be written above.
Java like all OO languages aims to regulate and stream-line
the way in which average developer thinks. It is true that
in real world (from software designer perspective), an
entity, an object does exhibit functions from seemingly
different sets (aka classes).
It is true that implementing multiple inheritance is
difficult at compiler level and complexity is hardly ever
clearly explained in any example. Every single example of
MI that demonstrates its complexity seems contrived and are
generally name-collisions. Assuming that I did seriously
want to inherit class C from both A and B, why on earth
would I give same names to two distinct functions
originating from class A and class B? One could be foo()
and other could be foofoo(); (I hope you get the drift).
C++ designers bent-over-their-back and solved the problem
of MI and even the diamond problem.
Although, Diamond problem is successfully handled by C++,
any sane designer team could have a coding standards that
favour avoidance Diamond inheritance until the die-hard
developer convinces upper crust of its essentials.
Ironically, the major part of Java's decision on "why" of
avoiding MI lies in C++ implementation of it.
While I am grossly simplifying here, Crux of C++ solution
of implementing MI under the hood hinges upon properly
managing the v-table at run-time and unambigious usage of
redundant methods ( in case of diamond) are handled.
In case of Java, design goal was operability across
multiple platforms and industrial strength stability.
Both of these goals can be seriously compromised if MI (and
C++ solution of v-table) were implemented.
Therefore, Java designers choose to let go of a smaller
nice-to-have feature (MI for classes) in favour of Multiple
Platform (essential design goal)
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / lalit sonje
There is another form of inheritance called as multiple
inheritance. This is not supported by java. The authors of
the java language took a design decision to compromise
multiple inheritance with interfaces, the specifics of this
decision may be covered in other sources. Practically,
multiple inheritances is difficult because of the
ambiguities, it can be created when a class inherits from
two super classes with the same method signature.
But there is a workaround for this problem. Java allows us
to achieve partial multiple inheritance using interfaces. A
class can implement any number of interfaces and provide
implementations for them and achieve partial multiple
inheritance.
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / velmurugan.p
basically java does not support multiple inheritance because
java extend only one class so we use interface in multiple
inheritance to define more than one class to avoid ambiguity.
Is This Answer Correct ? | 0 Yes | 1 No |
Answer / mustakim
because it genereate diamond problem. e.g. Class A has
Show()Method and Class B,C extends in A class so show() will
come in B,C class.now Class D extends C class and access
show() method then it will generate Error such as multiple
Defination.
Is This Answer Correct ? | 0 Yes | 1 No |
What methodology can be employed to locate substrings inside a string?
What does sprintf mean?
JVM responsibility?
Why parsing is done?
Explain inner classes ?
When a lot of changes are required in data, which one should be a preference to be used? String or stringbuffer?
What is the difference between static binding and dynamic binding?
can java object be locked down for exclusive use by a given thread? Or what happens when a thread cannot acquire a lock on an object? : Java thread
Does constructor be static?
JSP is by default thread safe or not? what is the meaning of isThreadSafe="true" and isThreadSafe="false". Explain it? Thanks, Seenu
Does java support Operator Overloading?
What is the purpose of stub and skeleton?