Java - Methods from Object Class

Category

Methods from Object class can be grouped into two categories.

  • Ready to use
  • Not Ready to use

The ready-to-use methods have been implemented in the Object class.

Methods that fall into this category are getClass(), notify(), notifyAll(), and wait().

The not-ready-to-use Methods have a default implementation in the Object class. You have to reimplement (override) them to get proper usage.

Methods that fall into this category are toString(), equals(), hashCode(), clone(), and finalize().

Method List

List of Methods in the Object Class with Their Brief Description

Method
Implemented
Customizable
Description
public String toString()


Yes


Yes


It returns a string representation of
an object. Typically, it is used for
debugging purpose.
public boolean equals(Object obj)

Yes

Yes

It is used to compare two objects for
equality.
public int hashCode()

Yes

Yes

It returns a hash code (an integer)
value of an object.
protected Object clone() throws
CloneNotSupportedException
No

Yes

It is used to make a copy of an object.

protected void finalize() throws
Throwable
No

Yes

It is called by the garbage collector
before an object is destroyed.
public final Class getClass()

Yes

No

It returns a reference to the Class
object of the object.
public final void notify()

Yes

No

Notifies one thread in the wait queue
of the object.
public final void notifyAll()

Yes

No

Notifies all threads in the wait queue of
the object.
public final void wait()
throws InterruptedException
Yes

No

Makes a thread wait in the wait queue
of the object with a timeout.
public final void wait(long timeout)
throws InterruptedException
Yes

No

Makes a thread wait in the wait queue
of the object without a timeout.
public final void wait
(long timeout, int nanos)
throws InterruptedException
Yes


No


Makes a thread wait in the wait queue
of the object with a timeout.

Related Topic