Why java Don't Support Multiple interitence

Answers were Sorted based on User's Feedback



Why java Don't Support Multiple interitence..

Answer / g ch vishnu vardhan reddy

Multiple Inheritance is not supported by java in order to
avoid ambiguity between variables of different classes and
to rudece memory overloading.

Is This Answer Correct ?    42 Yes 1 No

Why java Don't Support Multiple interitence..

Answer / bhaskar reddy

There is a big reason behind that(java does not support
multiple inheritance). Please go through the following
example.

1. Assume that java is supporting multiple inheritance

class A {

void m1() {
// implement method
}
}

class B {
void m1() {
// implement method
}
}
//As for the assumption (1) the following code will compile

class C extends A,B {

public static void main( String s[]) {

C c = new C();
c.m1();
}
}

Note : In main method i am calling c.m1() method In this
situation which super class m1 method has to call (from A
or B) JVM will confuse.

So our assumtion(1) is wrong .

This is the reason why java does not support multple
inheritance through classes.

Note : This same cocept is applicable for classes.

Is This Answer Correct ?    29 Yes 4 No

Why java Don't Support Multiple interitence..

Answer / midhula kadiyala

If you extend more than one class JVM does n't understand
for which object it has to create object first.so ambiguios
occurs.That's y java does n't support multiple inheritance.


We can implement multiple inheritance by using interfaces.

Interface A
{
public void X();
}
class B implements A
{

public void X()
{
s.o.p("this is function x");
}
public void Y()
{
s.o.p("this is function y");
}

}

class C extends B
{
public void X(){...}
public void j(){...}

P S V M()
{

A a =new C();
a.X();
}
}

if a class wants to extend 1 or more classes define those
function definitions in one interface and in another class
provide bodies by implementing those interface.

if the class can extend the class which is implementing that
interface then u can access all functions present in that
interface.


here my interface A

i provide bodies in class B by implementing interface A

class C extend that class B

and class c is able to access all the methods present in the
interface by creating the reference of an interface with the
object of class C

(remember 1 thing to the reference of interface we can
assign object of class only if it is implementing that
interface)

here class c extends class B and again class B implements

interface A

so i can write

A a= new C();

Is This Answer Correct ?    0 Yes 0 No

Why java Don't Support Multiple interitence..

Answer / sanjeev

Why cant we face same ambiguity when we declare variables?
interface A{
int i = 10;
}
interface B{
int i = 20;
}
Class C implement A, B{
what is the value of C.i?
}

Is This Answer Correct ?    0 Yes 1 No

Why java Don't Support Multiple interitence..

Answer / srinu

Java Does not support Multiple inhertiance through class
because ambiguity between variables of different classes
and to rudece memory overloading.and another reason java
extended only one class at time

java support Multiple inhertiance through interfaces.because
java class implements any number of interface at time

Is This Answer Correct ?    0 Yes 2 No

Why java Don't Support Multiple interitence..

Answer / kiranksj

ya java don't support multiple interitence but by achieving
it the interface are came

Is This Answer Correct ?    2 Yes 6 No

Why java Don't Support Multiple interitence..

Answer / sid

The famous "diamond shaped problem " is the reason behind NOT using multiple inheritance in java.
check out this link for full details
http://en.wikipedia.org/wiki/Diamond_problem

Is This Answer Correct ?    0 Yes 4 No

Why java Don't Support Multiple interitence..

Answer / samir rana

java support multiple inheritance not through the use of
class, but through the implementation of interface we can
achieve multiple inheritance.

By using interface we can implement multiple interfaces for
a class which can solve the problem of our multiple inheritance.

Is This Answer Correct ?    0 Yes 4 No

Post New Answer

More Core Java Interview Questions

Can you explain the private protected field modifier?

0 Answers  


What is the symbol for space?

0 Answers  


what is Assertion?

4 Answers   Wipro,


Explain Global variables in Packages?

4 Answers  


Can we increase size of array?

0 Answers  






Can we create constructor in abstract class ?

0 Answers  


What do you mean by stream pipelining in java 8?

0 Answers  


Differences between traditional programming language and object oriented programming language?

0 Answers  


What is getkey () in java?

0 Answers  


What is use of map in java?

0 Answers  


wahts is mean by thread?

22 Answers   HCL, TCS,


What are assertions in java?

1 Answers   Impetus,


Categories