Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inheritance of Object Class in Java

While i was reading java book, i came across "Every class extends class Object"...but if want a class B to extend class A.....but Class B will be now having multiple inheritance,one from Object class and one from Class A.How the conflict is resolved. Can anyone explain?

like image 562
user654761 Avatar asked Jan 19 '23 02:01

user654761


2 Answers

Its multi-level inheritance, not multiple:

class A extends Object

class B extends A

like image 144
Count Avatar answered Jan 20 '23 16:01

Count


First of all, Object class is the super/base/parent class of every class including user-defined classes.

So even if we don't mention it explicitly, the user-defined classes extends Object class by default.

Morevoer, Object class implements a set of methods and variables which are common to all the objects being created in the application. This is the main reason why we have Object class as a base class for all the other classes.

For eg:

hashCode() - this method creates a unique identity for each of the object being created in JVM.

like image 40
Mithun Sasidharan Avatar answered Jan 20 '23 15:01

Mithun Sasidharan