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

What is 16 bits called?

0 Answers  


Is binary a low level language?

0 Answers  


How do you check whether the list is empty or not in java?

0 Answers  


What is difference between classpath and path variables in java?

0 Answers  


What is __ init __ functions?

0 Answers  






Why are strings immutable in Java?

1 Answers  


What is the purpose of a parameter?

0 Answers  


What is += mean in java?

0 Answers  


Difference between stack and queue?

0 Answers   Flextronics,


can we create instance for interface in java?

4 Answers  


What is the use join() in Threads ?

5 Answers   HCL,


Explain OOPs concept.

0 Answers   Syntel, Visa,


Categories