Object Class in Java


An object class in java programming language is considered to be the parent class of all the classes in a program by default. The top most class of java programming language is the object class. The object class is advantageous when the type of an object is not known in the code. It should be noted here that the object or the reference variable of the object class can refer to all the parent classes; this concept is upcasting in Java.

Through an object class we can compare, clone and notify various objects.


Methods of Object class:

There are various methods that are provided by an object class. Following are some of them:

Method Description
public final Class getClass () This method is used to return the Class class object of this object.
public int hashCode () This method is used to return the hash code number for this object.
public Boolean equals (object obj) This method is used to compare the given object with this object.
protected object clone () throws CloneNotSupportedException This method is used to create and then return the clone or exact copy of the object.
public String toString () This method is used to return the string representation of this object.
public final void notify () This method is used to wake up the single thread.
public final void notifyAll () This method is used to wake up all threads.
public final void wait (long timeout) throws InterruptedException This method is used to make the current thread to wait for a specified small time period of milliseconds until another thread notifies.
public final void wait (long timeout, int nanos) throws InterruptedException This method is used to make the current thread to wait for a specified small time period of milliseconds until another thread notifies.
public final void wait () throws InterruptedException This method is used to make the current thread to wait for a specified small time period until another thread notifies.
protected void finalize()throws Throwable This method is called or invoked by the garbage collector.