We say that java follows a single inheritance model i.e. a Java class can extend only one class at max. and then say that every java class is inherited from Object class.
Suppose there are two classes A and B. Both A and B extend from Object. Now suppose A extends B. Doesn't it imply that A has multiple inheritence (A is inheriting from both B and Class Object)?
Object A extends object B which extends Object. It's not multiple inheritance, it's hierarchy
in your question
A directly inherit B
andObject class
is inherited by B not byA
..This is called transitive inheritanceMultiple Inheritance: (Not supported by Java)
Class A extends Object
Class B extends Object
Class C extends A, B
Multilevel/Transitive Inheritance:(Supported by Java)
Class B extends Object
Class A extedns B
Java doesn't let you extend more than 1 super-class. However, a class can implement multiple interfaces. You can create a structure of interfaces and abstract classes that let's you hack extending more than 1 class. Good luck!
Look at the difference between transitive inheritance (C inherits directly from B and transitively from A):
and multiple inheritance (C inheriting from both A and B):
Everything is just added on, except methods with the same signature, which are overridden. Even variables declared with the same name are added on, they're just said to be "hidden" but can still be accessed using casting, or the super keyword if it's the immediate parent.
The main problems with multiple inheritance is the ambiguity, when two classes define the same method and are being both overriden and the diamond problem. Java doesn't suffer from this as, it allows overriding only a single class. This obviously refers to direct overriding and doesn't deal with hierarchies of inheritance. This kind of inheritance (A overring B, B overriding and so on) isn't affected by any problems.