javaoop

Multiple Inheritance and class Object


I am pretty new to OOP. We all know that Java does not support multiple inheritance; however, all Java classes inherit from Object and can also inherit from another class. Can we consider this as multiple inheritance? How does Java handle such a thing?


Solution

  • It's not multiple inheritance it's multi level inheritance. Classes can extend one other class, which can extend one other class, ..., which ultimately extends Object:

    A --> B --> C --> Object
    

    Multiple inheritance would be

    A ----> B 
      \
       \--> C
    

    This means that when a method or a field is used inside A, it's looked up in A, then in B, then in C, then in Object.

    With multiple inheritance, it would have to be looked up in A, then in B and C, and there could be a conflict because the same method or field could exist in both superclasses.