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

Does isempty check for null?

0 Answers  


What do you mean by flow of struts?

0 Answers   Amdocs,


What is object english?

0 Answers  


What is a condition in java?

0 Answers  


what is the use of custom tags? with example?

1 Answers   Photon,






Is java ee a framework?

0 Answers  


How do you remove spaces in java?

0 Answers  


aabccdee Find the used alphabets as abcde ?

4 Answers  


What is volatile data type?

0 Answers  


What is multithreading ???? How to stop multithrading in java????

1 Answers   Cognizant,


How do you compare characters in java?

0 Answers  


What does regex mean?

0 Answers  


Categories