why java does not support multiple inheritance

Answers were Sorted based on User's Feedback



why java does not support multiple inheritance..

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

why java does not support multiple inheritance..

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

why java does not support multiple inheritance..

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

why java does not support multiple inheritance..

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

why java does not support multiple inheritance..

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

why java does not support multiple inheritance..

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

why java does not support multiple inheritance..

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

why java does not support multiple inheritance..

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

why java does not support multiple inheritance..

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

why java does not support multiple inheritance..

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

Post New Answer

More Core Java Interview Questions

Can we have a method name same as class name in java?

0 Answers  


Can we clone singleton object?

0 Answers  


What is n in java?

0 Answers  


If try block is successfully executed, Then Is Finally block executed?

0 Answers   PUCIT,


Explain the features of interfaces in java?

0 Answers  






What is tcp ip in java?

0 Answers  


Can we declare a class as abstract without having any abstract method?

0 Answers  


Can an interface implement another interface?

0 Answers  


What exactly is methodology?

0 Answers  


Does java trim remove newline?

0 Answers  


How many decimal places is a double?

0 Answers  


How many bits are allocated to represent character of character sets - Unicode, ASCII, UTF-16, UTF-8?

1 Answers  


Categories