I have confusion in Java inheritance. As I studied Java does not support multiple inheritance. So that it does not have the diamond problem of inheritance at all.
But, every class of Java inherits the Object class by default, and if we extend a class then there are two inherited classes first is Object and second is our inherited class. As I know if any class inherits two or more classes, it’s known as multiple inheritance. It shows that Java supports multiple inheritance, because it’s inheriting two classes at same time.
Then why it’s said that Java does not support multiple inheritance and is there a possibility to have the diamond problem in Java?
That’s partially correct.
If you extend a class explicitely, then it won’t extend
Objectclass.if you have a class
then, compiler will change it into
But, if you extends a class explicitely, as following,
compiler won’t add anything now, hence No multiple inheritance.