Why java does not supports multiple inheritance?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Hi friends am new to java. I read jar file means collection of java files. For executing struts application what are the necessary jar files. " struts.jar " file contains what. can u explain

1424


What is final method?

576


Explain the access modifiers for a class, method and variables?

645


Give example to differentiate between call by value and call by reference.

582


What is a stringbuilder?

498






What is the difference between a method and a procedure?

536


Write an algorithm for quick sort?

608


Why java is secure? Explain.

581


What is anti pattern in programming?

490


Can we able to pass objects as an arguments in java?

528


What is the difference between a checked and an unchecked exception?

541


Is 9 a prime number?

460


Can we have try block without catch block?

576


How finally used under exception handling?

503


What is the difference between an if statement and a switch statement?

639