why java does not support multiple inheritance

Answers were Sorted based on User's Feedback



why java does not support multiple inheritance..

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

why java does not support multiple inheritance..

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

why java does not support multiple inheritance..

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

why java does not support multiple inheritance..

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

why java does not support multiple inheritance..

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

why java does not support multiple inheritance..

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

why java does not support multiple inheritance..

Answer / vishwanath

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

why java does not support multiple inheritance..

Answer / karthikeyan

Java does not support Multiple inheritance Directly, But it
will support indirectly through Interface.

Is This Answer Correct ?    7 Yes 3 No

why java does not support multiple inheritance..

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

why java does not support multiple inheritance..

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

Post New Answer

More Core Java Interview Questions

Which is fastest collection in java?

0 Answers  


What is a static class in java?

0 Answers  


what is wrapper class and its uses?

2 Answers  


Say you want to store the information about a number of pets in an array. Typical information that you could store for each pet (where relevant) would be • Breed of animal • Animal's name • Its birth date • Its sex • Whether it has been sterilised or not • When it is due for its next inoculation • When it last had its wings clipped For each type of pet (eg. dog, cat or bird) you would typically define a class to hold the relevant data. Note: You do not need to implement these classes. Just answer the following questions. 3.1.1 What would be the advantage of creating a superclass (eg. Pet) and declaring an array of Pet objects over simply using an array of Objects, storing each of the instances of the different pet classes (eg. Dog, Cat or Bird) in it? 3.1.2 Would you define Pet as a class or as an interface? Why? (2) (2)

0 Answers  


How do you define a method?

0 Answers  






What is a default package ?

7 Answers  


Why does my function print none?

0 Answers  


What is int short for?

0 Answers  


What are the legal parameters?

0 Answers  


How to initialize an Applet ?

9 Answers   TCS,


What is a top level class in java?

0 Answers  


Explain about instanceof operator in java?

0 Answers  


Categories