How can the Object class be a super class of subclasses?

  • A+
Category:Languages

Fact 1:

Java does not support multiple inheritance.

Fact 2:

Object is a superclass of all other classes

If I have a class Parent and a class Child which is inheriting class Parent:

class Parent {  }  class Child extends Parent {  } 

In this case, how will class Child inherit the Object class, if Java does not support multiple inheritance?

How is the relationship between these three defined?

Option 1:

How can the Object class be a super class of subclasses?

Option 2:

How can the Object class be a super class of subclasses?

 


It's Option 2. If you define a superclass, that will be the immediate superclass of your class. If you don't define one, Object will be the immediate superclass.

class Parent {  }  class Child extends Parent {  } 

is equivalent to

class Parent extends Object {  }  class Child extends Parent {  } 

So, while Object is the superclass of all classes, there might be some steps in the class hierarchy before you get to Object. It's not the immediate superclass of all classes.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: