7.3 How to Read a Class Hierarchy | 335
herited by JTextField. We won’t list them here, but among them is getText. We also see other
methods in JTextComponentwhose names imply that they manipulate text within the field.
The class heading for JTextComponentindicates that the story continues, because it extends
the class JComponent. If we look at the documentation for that class, we find that it defines
138 more methods. We’ll look at just one of them here, together with its heading:
public abstract classJComponent extendsContainer
{
public voidsetVisible(booleanflag);
.
.
.
}
Notice the use of the abstractmodifier in the class heading. Whenever you see the key-
word abstractin a class declaration, it tells you that the class being defined is incompletely
specified and cannot be instantiated.
When a class is declared as abstract, its purpose is to provide a placeholder for a defi-
nition to be supplied in a derived class. The class JComponentdoesn’t have any constructors.
It doesn’t define the structure of a useful object that we can instantiate. Instead, it defines
a collection of methods that are common to various objects that can appear in a window. By
deriving classes for those objects from this common class, Java makes it easy to ensure that
they all behave in a consistent manner.
As we can see from its definition,JComponentextendsContainer. Looking at Container,we
see that it defines another 51 methods; it also extendsComponent, which in turn supplies an-
other 138 methods. Finally,ComponentextendsObject, which is the top of the entire hierarchy
and supplies another 10 methods. We rarely use Object’s methods directly, and several of them
are related to features of Java that are beyond the scope of this text. Here we list just the ones
that are familiar:
public classObject
{
publicObject(); // Constructor
public booleanequals(Object obj);
publicString toString();
.
.
.
}
Now that we have the specification for every class that is an ancestor ofJTextField,we
can determine the methods that it has available. There are more than 400 methods that it may
inherit. We could begin at the bottom of the hierarchy (JTextField) and write a list of all of its
members as a column on one side of the page. In the next column, we would write the mem-
bers of its superclass (excluding its constructors, because constructors technically aren’t