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.

Methods from Object class

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( ).

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.