0

As Object class is the base of every class, can we conclude JAVA is supporting multiple inheritance for a Cat class extending Animal class.

I read on explanation on page(Inheritance in java and Superclasses(Object, Class)).

But to my understanding it seems too me like below:

   Object

   ^    ^

Animal   ^ 

   ^    ^ 

    Cat
Flown
  • 11,480
  • 3
  • 45
  • 62
nitz
  • 27
  • 4
  • Object is parent of Animal class.Cat extends Animal class. Thus, hierarchy is as follows: Object->Animal-> Cat. Java is following a single inheritance hierarchy. Its only when its like Man extends Monkey, Ape {} that we call as multiple inheritance. – akshaya pandey Nov 08 '17 at 10:00
  • 1
    Well, not quite! `Cat` does not directly inherit from `Object`. So this is not multiple Inheritance. – Prashant Nov 08 '17 at 10:01

2 Answers2

0

Multiple inheritance refers to a class inheriting directly from two classes. Single inheritance in Java means that you can always have only ONE parent. You would have still many ancestors. Object will always be the first ancestor in the line of inheritance. In Java, you cannot inherit Cat from Animal and HashMap at the same time for example. A real life example would be a child who inherits features from mum and dad. But with Java, that's not possible.

Mick
  • 954
  • 7
  • 17
0

If you don't specify any superclass in the extends clause, you extend from Object directly. If you specify a class in the extends clause, you extend from this class, which extends its own superclass, etc., until Object.

Aarif Aslam
  • 1,077
  • 10
  • 15