Object

Name

Object

Synopsis

Description

The Object class is the ultimate superclass of all other classes in Java. Because every other class is a subclass of Object, all of the methods accessible from Object are inherited by every other class. In other words, all objects in Java, including arrays, have access to implementations of the methods in Object.

The methods of Object provide some basic object functionality. The equals() method compares two objects for equality, while the hashCode() method returns a hashcode for an object. The getClass() method returns the Class object associated with an object. The wait(), notify(), and notifyAll() methods support thread synchronization for an object. The toString() method provides a string representation of an object.

Some of these methods should be overridden by subclasses of Object. For example, every class should provide its own implementation of the toString() method, so that it can provide an appropriate string representation.

Although it is possible to create an instance of the Object class, this is rarely done because it is more useful to create specialized objects. However, it is often useful to declare a variable that contains a reference to an Object because such a variable can contain a reference to an object of any other class.

Class Summary

public class java.lang.Object {
 // Constructors public Object(); // Public Instance Methods public boolean equals(Object obj);
public final native Class getClass();
public native int hashCode();
public final native void notify();
public final native void notifyAll();
public String toString();
public final native void wait();
public final native void wait(long millis);
public final native void wait(long millis, int nanos); // Protected Instance Methods protected native Object clone(); protected void finalize() throws Throwable;
}

Constructors

Object

public Object()

Public Instance Methods

equals

public boolean equals(Object obj)

getClass

public final native Class getClass()

hashCode

public native int hashCode()

notify

public final native void notify()

notifyAll

public final native void notifyAll()

toString

public String toString()

wait

public final native void wait() throws InterruptedException

public final native void wait(long timeout) throws InterruptedException 

public final native void wait(long timeout, int nanos) throws InterruptedException 

Protected Instance Methods

clone

protected native Object clone() throws CloneNotSupportedException

finalize

protected void finalize() throws Throwable

See Also

Equality Comparison Operators; Exceptions; Object Destruction; The finalize method; String; Threads 8; Throwable