why java does not support multiple inheritance
Answers were Sorted based on User's Feedback
Answer / kishore
Java absolutly support multiple inheritence in terms of
Interface.We can extend one class only to avoid ambiguity
problem.In interface we have to define the functions.So we
don't get any ambiguity.In c++ it is big problem with
multiple inheritence but in JAVA this thing is improved by
introducing Interfaces
Is This Answer Correct ? | 304 Yes | 88 No |
Answer / sskur
To say why java doesn't support inheritance directly like c++
should be the diamond problem faced by c++,
(Diamond problem is an ambiguity that arises when two
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 it), and B and C have overridden that
method differently, then via which class does it inherit: B,
or C?)
Is This Answer Correct ? | 206 Yes | 22 No |
Answer / smitha
Java supports multiple inheritence indirectly through the
use of interface. In case we are able to extend more than
one class then there would be a confusion of which method to
process in case both classes have same method name(Same
method signature also).
In case of using interfaces to support multiple inheritance
we escape this problem as we define the methods that are
needed only.
Is This Answer Correct ? | 232 Yes | 54 No |
Answer / mukul
java does not supports multiple inheritence at all.but it
supports similar feature interface.Which removes the
ambiguity problem(Deadly Diamonds Of Death) and complexity
of multiple inheritence.Although interface is not the part
of inheritence because inheirtence is achieved in java
through extends keyword only.Interface is the part of
aggregation not inheritence.
Is This Answer Correct ? | 47 Yes | 13 No |
Answer / priyanka
Multiple inheritance means derive class from multiple
classes but java can't extend multiple classes. it can
extend one class but multiple interfaces. so create
multiple interfaces n then implement it.
Java have such fzacility to avoid ambiguty.
Thank u
Is This Answer Correct ? | 35 Yes | 17 No |
Answer / shiva
multiple inheritance means a sub class which is derived from
two base classes.
assume that the two base classes has same methods with same
signature.
for eg we create an object for the base class.
now call the any one method of base class with sub class object.
now which method is going to execute?
To avoid this confusion java doesnot support multiple
inheritance.
Is This Answer Correct ? | 22 Yes | 6 No |
java doesn't support multiple inheritance directly because it leads to overiding of methods when both extended class have a same method name. this will leads to ambiguity in executing. this problem can be solved using interface which works similar to the multiple inheritance but the methods are defined in the subsequent classes so it does not create any ambiguity.
Is This Answer Correct ? | 8 Yes | 0 No |
Answer / karthikeyan
Java does not support Multiple inheritance Directly, But it
will support indirectly through Interface.
Is This Answer Correct ? | 7 Yes | 3 No |
Answer / priyanka patil
The reasons for omitting multiple inheritance from the Java
language mostly stem from the "simple, object oriented, and
familiar" goal. As a simple language, Java's creators
wanted a language that most developers could grasp without
extensive training. To that end, they worked to make the
language as similar to C++ as possible (familiar) without
carrying over C++'s unnecessary complexity (simple).
In the designers' opinion, multiple inheritance causes more
problems and confusion than it solves. So they cut multiple
inheritance from the language (just as they cut operator
overloading). The designers' extensive C++ experience
taught them that multiple inheritance just wasn't worth the
headache.
Instead, Java's designers chose to allow multiple interface
inheritance through the use of interfaces, an idea borrowed
from Objective C's protocols. Multiple interface
inheritance allows an object to inherit many different
method signatures with the caveat that the inheriting
object must implement those inherited methods. Multiple
interface inheritance still allows an object to inherit
methods and to behave polymorphically on those methods. The
inheriting object just doesn't get an implementation free
ride
Is This Answer Correct ? | 6 Yes | 4 No |
Answer / rajiv
java does not support multiple inheritance because it does
not meet object oriented specification. Due to ambiguity
problem will arise if two or more superclass have the same
method name, and the super keyword will not be able to
decide which superclass to call. so we use interface to
solve this problem.
Is This Answer Correct ? | 4 Yes | 3 No |
What is a cup of java?
What are different access specifiers in java? Explain
What is the method to expand and collapse nodes in a jtree?
Write java code to print "Hello how are you" Thread1 should have "Hello" Thread2 should have "how are you" both the threads should start at the same time
What are the six ways to use this keyword?
why java does compile time polymorphism at run time ?
What are Normalization Rules? Define Normalization?
What is the scope or life time of instance variables?
What is abstraction with strong example program? (not a general program)
What is a ternary operator in java? What is an interface?
What is the difference between method overriding and overloading?
What is default specifier ??? Use of default specifier ???