Java Reference
In-Depth Information
The final modifier can also be applied to an entire class. A final class cannot
be extended at all. Consider the following declaration:
public final class Standards
{
// whatever
}
Given this declaration, the Standards class cannot be used in the extends
clause of another class. The compiler will generate an error message in such a
case. The Standards class can be used normally, but it cannot be the parent of
another class.
Using the final modifier to restrict inheritance abilities is a key design decision. It
should be done in situations in which a child class could possibly be used to change
functionality that you, as the designer, specifically want to be handled a certain way.
This issue comes up again in the discussion of polymorphism in Chapter 10.
SELF-REVIEW QUESTIONS (see answers in Appendix N)
SR 9.18 What does it mean for an inheritance derivation to represent an is-a
relationship?
SR 9.19 Where should common features of classes appear in a class hierarchy?
Why?
SR 9.20 How can you define a class with multiple roles?
SR 9.21 Why should you override the toString method of a parent in its child
class, even when the method is not invoked through the child by your
current applications?
SR 9.22 How can the final modifier be used to restrict inheritance? Why
would you do this?
9.6 The Component Class Hierarchy
All of the Java classes that define GUI components are part
of a class hierarchy, shown in part in Figure 9.7. Almost all
Swing GUI components are derived from the JComponent
class, which defines how all components work in general.
JComponent is derived from the Container class, which in
turn is derived from the Component class.
You'll recall that there are two primary GUI APIs used in Java: the Abstract
Windowing Toolkit (AWT) and the Swing classes. The AWT is the original set of
KEY CONCEPT
The classes that represent Java GUI
components are organized into a
class hierarchy.
 
Search WWH ::




Custom Search