Object Class

Package: java.lang

Object is the mother of all classes. Every class ultimately inherits the Object class. This class provides a set of methods available to every Java object.

Methods

Method

What It Does

protected Object clone()

Returns a copy of this object.

boolean equals(Object obj)

Indicates whether this object is equal to the obj object.

protected void finalize()

Is called by the garbage collector when the object is destroyed.

Class getClass()

Returns a Class object that represents this object’s runtime class.

int hashCode()

Returns this object’s hash code (a calculated value that uniquely identifies the object).

void notify()

Is used with threaded applications to wake up a thread that’s waiting on this object.

void notifyAll()

Is used with threaded applications to wake up all threads that are waiting on this object.

String toString()

Returns a String representation of this object.

void wait()

Causes this object’s thread to wait until another thread calls notify or notifyAll.

void wait(Long timeout)

Is a variation of the basic wait method.

void wait(Long timeout, int nanos)

Is yet another variation of the wait method.

Using Object as a type

If you don’t know or care about the type of an object referenced by a variable, you can specify its type as Object. The following example is perfectly legal:

Object emp = new Employee();

You can’t do anything useful with the emp variable, ...

Get Java For Dummies Quick Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.