Why java does not supports multiple inheritance?

Answers were Sorted based on User's Feedback



Why java does not supports multiple inheritance?..

Answer / instanceofjava

Inheritance:

The concept of getting properties of one class object to another class object is known as inheritance.
Here properties means variable and methods.

Types of Inheritance:

Multiple inheritance.
Multilevel inheritance.

Multiple inheritance:

The concept of Getting the properties from multiple class objects to sub class object with same priorities is known as multiple inheritance.
Java Doesn't Support multiple Inheritance.

Diamond problem:

In multiple inheritance there is every chance of multiple properties of multiple objects with the same name available to the sub class object with same priorities leads for the ambiguity.

//Multiple inheritance program
Class A{
}
Class B extends A{
public void show(){
}
}
Class C extends A{
public void show(){
}
}
Class D extends B,C{ // not supported by java leads to syntax error.
}

Why multiple inheritanc eis not possible in java

We have two classes B and c which are inheriting A class properties.
Here Class D inheriting B class and C class So properties present in those classes will be available in java.










more http://www.instanceofjava.com/2014/12/why-java-does-not-supports-multiple.html

Is This Answer Correct ?    15 Yes 0 No

Why java does not supports multiple inheritance?..

Answer / mahendra kola

Java Does not support multiple inheritance because java is a simple programming language, but here may be we can get ambiguity

The process of getting variable and methods from more then one class to one or more number of sub classes is called as multiple inheritances.
if we write java program like bellow we get ambiguity problem ....
class A
{
public int n=10;
public void m1(){
System.out.println("A class Method");
}
}
class B
{
int n=20;
public void m1(){
System.out.println("B class Method");
}
}
class C extends A,B
{
System.out.println(n);
public static void main(String[] args){
System.out.println("Child Class");
}

}


• Incase of multiple inheritance, if declare the same variables with deferent values and same methods with different with implementation at two super classes then if we access that variables and methods at the respective subclass then which super class variable will be accessed and which super class methods will be accessed is a confusion state.
• Java is a simple programming language, it should not allowed confusion oriented features, due to this reason, java has not allowed multiple inheritances.

Is This Answer Correct ?    1 Yes 0 No

Why java does not supports multiple inheritance?..

Answer / shree

Multiple inheritance eliminated from java because it leads to confusion in many of cases & causes ambiguity.
So to avoid that complexity java does not support multiple inheritance.

/Multiple inheritance program
Class A
{
public void show(){.....}
}

Class B extends A
{
public void show(){.....}
}

Class C extends A{
public void show(){......}
}
Class D extends B,C{ // not supported by java leads to syntax error.
}


Here class D will get confuse which show() method to execute as there are 2 show() methods are available inherited from class B & C.


but to provide functionality of inheritance java provides new concept called INTERFACE.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

Is space a char?

0 Answers  


Can we pass null as argument in java?

0 Answers  


What is the difference between == and === javascript?

0 Answers  


Can an exception be rethrown?

4 Answers   Wipro,


What is the preferred size of a component?

3 Answers   ITSA,






what do you mean by stream pipelining in java 8? Explain

0 Answers  


what are the differences between final,finally,finalize methods?

14 Answers   IBM,


Why can't you declare a class as protected?

0 Answers  


Difference between canvas class & graphics class?

1 Answers  


Can private class be extended java?

0 Answers  


In Java list the methods that can be overridden?

0 Answers   Accenture,


which method is used to know the status of the Thread?

9 Answers   Honeywell,


Categories