The Ultimate Superclass

A class that does not explicitly extend another class implicitly extends Java's Object class (located in the java.lang package—I will discuss packages in the next chapter). For example, Listing 3-1's Vehicle class extends Object, whereas Car extends Vehicle.

Object is Java's ultimate superclass because it serves as the ancestor of every other class, but does not itself extend any other class. Object provides a common set of methods that other classes inherit. Table 3-1 describes these methods.

Table 3-1. Object's Methods

Method

Description

Object clone()

Create and return a copy of the current object.

boolean equals(Object obj)

Determine if the current object is equal to the object identified

by obj.

void finalize()

Finalize the current object.

Class<?> getClass()

Return the current object's Class object.

int hashCode()

Return the current object's hash code.

void notify()

Wake up one of the threads that are waiting on the current

object's monitor.

void notifyAll()

Wake up all threads that are waiting on the current object's

monitor.

String toString()

Return a string representation of the current object.

void wait()

Cause the current thread to wait on the current object's monitor

until it is woken up via notify() or notifyAll().

void wait(long timeout)

Cause the current thread to wait on the current object's monitor

until it is woken up via notify() or notifyAll(), or until the

specified timeout value (in milliseconds) has elapsed,

whichever comes first.

void wait

Cause the current thread to wait on the current object's monitor

(long timeout, int nanos)

until it is woken up via notify() or notifyAll(), or until the

specified timeout value (in milliseconds) plus nanos value (in

nanoseconds) has elapsed, whichever comes first.

I will discuss getClass(), notify(), notifyAll(), and the wait() methods in Chapter 7.

I will discuss getClass(), notify(), notifyAll(), and the wait() methods in Chapter 7.

Was this article helpful?

0 0

Post a comment