Ankit Verma
Ankit Verma
9 years ago

Why Object is base class in java language?

Solution(By Examveda Team)

java.lang.Object class is the super base class of all Java classes. Every other Java classes descends from Object.
If a class is declared without extending another class then it will implicitly extend Object class. This is taken care of by the JVM. This is not applicable for the interfaces. A Java interface does not extends the Object.
Following could be the reasons for this design decision,


1.By having the Object as the super class of all Java classes, without knowing the type we can pass around objects using the Object declaration.


2.Before generics was introduced, imagine the state of heterogeneous Java collections. A collection class like ArrayList allows to store any type of classes. It was made possible only by Object class hierarchy.


3.    The other reason would be to bring a common blueprint for all classes and have some list of functions same among them. I am referring to methods like hashCode(), clone(), toString() and methods for threading which is defined in Object class.

 


This Question Belongs to User Ask Question >> Miscellaneous

Join The Discussion

Related User Ask Questions