+ 2
Can someone explain me this please?
Java don't support multiple inheritance of classes
3 Answers
+ 5
Let's one example to understand why java does not support multiple inheritance of classes.
ïžWe have three classes A,B and Main
// class A
class A {
public void printSomething() {
System.out.println("Hello");
}
}
// class B
class B {
public void printSomething() {
System.out.println("Hi");
}
}
// class Main
class Main extends A,B {
/*
if we extends like this First of all we get error C.E!
Let's say we are not getting error here.
*/
public static void main (String args[]) {
Main obj = new Main();
obj.printSomething();
/*
At the time of function calling. We don't know which class functions will be call. In this case Ambiguity will occur. that's why java doesn't support multiple inheritance of classes.
*/
}
}
+ 4
Yes, Java doesn't support multiple inheritance.
According to Google, multiple inheritance is much complex at run time and have conflictions issues
Also, it's not widely used so Java developers decided not to allow it.
+ 3
It is not that it is not widely used but it has ambiguity issues or the diamond problem like most of them call it which makes it not so suitable for use.
So interfaces take that responsibility.
Hichem GOUIA kindly take a look at this thread for a better understanding.
https://www.sololearn.com/Discuss/2115711/?ref=app