Java Reference
In-Depth Information
Resumes execution of all threads waiting on the in-
voking object.
void notifyAll( )
String toString( )
Returns a string that describes the object.
void wait( )
void wait(long milliseconds )
void wait(long milliseconds , int
nanoseconds )
Waits on another thread of execution.
The methods getClass( ) , notify( ) , notifyAll( ) , and wait( ) are declared as final . You
can override the others. Several of these methods are described later in this topic. However,
notice two methods now: equals( ) and toString( ) . The equals( ) method compares two
objects. It returns true if the objects are equivalent, and false otherwise. The toString( )
method returns a string that contains a description of the object on which it is called. Also,
this method is automatically called when an object is output using println( ) . Many classes
override this method. Doing so allows them to tailor a description specifically for the types
of objects that they create.
One last point: Notice the unusual syntax in the return type for getClass( ) . This relates
to Java's generics feature. Generics allow the type of data used by a class or method to be
specified as a parameter. Generics are discussed in Chapter 13 .
Chapter 7 Self Test
1 . Does a superclass have access to the members of a subclass? Does a subclass have ac-
cess to the members of a superclass?
2 . Create a subclass of TwoDShape called Circle . Include an area( ) method that com-
putes the area of the circle and a constructor that uses super to initialize the
TwoDShape portion.
3 . How do you prevent a subclass from having access to a member of a superclass?
4 . Describe the purpose and use of the two versions of super described in this chapter.
5 . Given the following hierarchy:
Search WWH ::




Custom Search