The Object Class

Object is a superclass of all other classes. Therefore, Object can refer to an object of any other class. Also, a variable of type Object can also refer to any array.

Object defines the following methods, which means that they are available in every object.

ReturnMethodPurpose
Objectclone( )Creates a new object that is the same as the object being cloned.
booleanequals(Object object)Determines whether one object is equal to another.
voidfinalize( )Called before an unused object is recycled.
ClassgetClass( )Obtains the class of an object at run time.
inthashCode( )Returns the hash code associated with the invoking object.
voidnotify( )Resumes execution of a thread waiting on the invoking object.
voidnotifyAll( )Resumes execution of all threads waiting on the invoking object.
StringtoString( )Returns a string that describes the object.
voidwait( )Waits on another thread of execution.
voidwait(long milliseconds)Waits on another thread of execution.
voidwait(long milliseconds, int nanoseconds)Waits on another thread of execution.

getClass( ), notify( ), notifyAll( ), and wait( ) are final.

The equals( ) method compares the contents of two objects.

It returns true if the objects are equivalent, and false otherwise.

The toString( ) method returns a string that contains a description of the object.

toString( ) method is automatically called when an object is output using println( ).

Home 
  Java Book 
    Class  

Object class:
  1. The Object Class
  2. Using clone( ) and the Cloneable Interface