Name
Object
Synopsis
This is the root class in Java. All
classes are subclasses of Object, and thus all
objects can invoke the public and
protected methods of this class. For classes that
implement the Cloneable interface, clone(
) makes a byte-for-byte copy of an
Object. getClass(
)
returns the Class
object associated with any Object, and the
notify( )
,
notifyAll( ), and wait( )
methods are used for
thread synchronization on
a given Object.
A number of these Object methods should be
overridden by subclasses of Object. For example, a
subclass should provide its own definition of the
toString( ) method so
that it can be used with the string concatenation operator and with
the PrintWriter.println( ) methods. Defining the
toString( ) method for all objects also helps with
debugging.
The default implementation of the equals( ) method
simply uses the = = operator to test whether this
object reference and the specified object reference refer to the same
object. Many subclasses override this method to compare the
individual fields of two distinct objects (i.e., they override the
method to test for the equivalence of distinct objects rather than
the equality of object references).
Some
classes, particularly those that override equals(
), may also want to override the hashCode(
) method to provide an appropriate hashcode to be used when
storing instances in a Hashtable data structure.
A class that allocates system resources other than memory (such as file descriptors or windowing system ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access