How does a class extending another class extend the Object class, although multiple inheritance is not allowed?

Since I am new to java. I want to know if multiple ineritance in java does not support how a class extends another class along with a superclass object by default?

+4
source share
4 answers

Since multiple inheritance is not allowed, one class can inherit from another, which can inherit from another, and ultimately, the class at the top of this chain inherits the object (it will do this if you do not specify any specific class to inherit from. )

+5
source

Although this has already been answered, there is another perspective. Try to think about it from a human point of view. You cannot have two biological fathers, but you inherit traits from your father, your grandfather, great-grandfather, etc. In the same way, when you extend a class, this class becomes the parent class, and you will inherit the traits from each parent class to the tree.

;)

+3
source

There are two similar sound concepts associated with multiple inheritance and multi-level inheritance.

In java, multiple inheritance is not allowed. This stops the class from inheriting multiple classes. For example, we cannot declare a class as follows:

Class C extends A, C 

But since multilevel inheritance is allowed, an extension of class B is allowed, which extends class A, by class C. Thus, class hierarchies such as

 Class B extends A 

and

 Class C extends B 

allowed.

+2
source

"Multiple inheritance" is different from what you describe - this refers to a single class that spans more than one class, for example

Public class MultipleClass extends ClassA, ClassB

What you described is simply a hierarchy of inheritance.

0
source