The Object
class is the root class of all Java classes. Every class in Java directly or indirectly inherits from it.
Key Methods:
toString()
:- Returns a string representation of the object.
equals(Object obj)
:- Compares two objects for equality.
hashCode()
:- Returns the hash code of the object.
getClass()
:- Returns the runtime class of the object.
clone()
:- Creates a copy of the object (requires
Cloneable
interface).
- Creates a copy of the object (requires
finalize()
:- Called before garbage collection.
Example:
The Object
class ensures consistency and interoperability in Java’s class hierarchy.