What is the base class for all classes?
In Java, Object Class is known as the base class for classes. This class is present in the default package of java which is java.lang.Object. which is why you don’t need to inherit this class. But each and every class in Java inherit it implicitly. You can always check that just by just typing the following command in the command prompt :
javap -c <.class name>
Why is object class base for all classes?
I believe that the designer’s of Java asked themselves the question – “What functionality do we want from every object of every class in Java?” And the small set of methods which they found were included in this super ancestor class of Java (The “Adam” class of Java).
1. First Purpose
We know that in inheritance subclass gets all behavior of its parent class. Similarly there are some behaviors that are exhibited by all object. If we take real world scenario, every entity has Meta-data. Meta-data like every real world entity has its unique identity like every human being has its own DNA variation, In the same way every object has its own hashcode in case of java.In real world every living being has its own species name and nomenclature, similarly in java every object has class. so we have getClass() method for it. In order that all objects show such behavior their classes implicitly inherits Object class2.
2. Second Purpose
In order to maintain proper hierarchy of classes in API, Object Class acts as the ROOT of the tree. Which helps in proper classification of Classes in API.
How does this help us?
By having Object class as base class, we can pass objects around without knowing their type using object declaration. Object class made it possible to create collection classes allowing us to store various classes for example ArrayList.