Javatpoint Logo

Why Java does not Multiple inheritance?

By: sam.mi*** On: Tue Jun 23 00:12:41 IST 2015     Question Reputation0 Answer Reputation0 Quiz Belt Series Points0  0Blank User
Sir,i know because of ambiguity error....

but it is like a symptom to a disease not the cause.i know that if i uses M.I. ambiguity error will take place but i want to know the reason?
Up0Down

 
If we declare one class by implementing two super class and we create object of subclass then constructor of which super class will be invoked by subclass constructor to initialize the all property. so It will give the constructor chaining issue. that is the reason Java doesn't support multiple inheritance.

for ex:

class A {
A(){}
}
class B {
B(){}
}

class C implements A, B{
C(){
super(); // Here Constructor chaining problem
}
}
Image Created0Down

By: [email protected] On: Tue Jun 23 15:06:56 IST 2015 Question Reputation0 Answer Reputation0 Belt Series Points0 0User Image
Are You Satisfied :0Yes0No
 
If we declare one class by implementing two super class and we create object of subclass then constructor of which super class will be invoked by subclass constructor to initialize the all property. so It will give the constructor chaining issue. that is the reason Java doesn't support multiple inheritance.

for ex:

class A {
A(){}
}
class B {
B(){}
}

class C implements A, B{
C(){
super(); // Here Constructor chaining problem
}
}
Image Created0Down

By: [email protected] On: Tue Jun 23 15:10:04 IST 2015 Question Reputation0 Answer Reputation0 Belt Series Points0 0User Image
Are You Satisfied :0Yes0No
 
if both bases calsses having the same method means The JVM confuses which method that is going to invoke.
EX:
class A
{
public void Hi()
{
System.out.println("A Class");
}
}

class B
{
public void Hi()
{
System.out.println("B Class");
}
}

class MainClass extends A,B//JVM confuse here , which method need to invoke.
{
public static void main (String args [])
{

}
}
Image Created0Down

By: [email protected] On: Wed Jul 22 15:43:07 IST 2015 Question Reputation0 Answer Reputation0 Belt Series Points0 0User Image
Are You Satisfied :0Yes0No