Why Java doesn't support multiple inheritance ?

  • Multiple inheritance causes more problems and confusion than it solves
  • The designers' extensive C++ experience taught them that multiple inheritance just wasn't worth the headache.
  • Multiple interface inheritance still allows an object to inherit methods and to behave polymorphically on those methods.
For Example

Suppose java had multiple inheritance like below

public class Parent1 {
public void method() {
System.out.println("Call me - I'm your Parent");
}
}
public class Parent2 {
public void method() {
System.out.println("He is not. Call me - I'm your Parent");
}

public class Child extends Parent1, Parent2 {
public static void main(String args[])
{
method();//Who's method should i call ?
}
}


Hence java doesn't support multiple inheritance.

No comments:

Post a Comment