•A public component —a component declared with modifier public — is
•A protected component —a component declared with modifier protect-
ed — of a class C is accessible in subclasses of C and in classes in the same
package as C .
•A package component —a component declared without an access modi-
fier— of a class C is accessible in classes in the same package as C .
•A private component —a component declared with modifier private —
of a class C is accessible only in class C .
With most of the programs that you write, you do not use a package state-
ment, so all the classes are automatically in the default package. Since all your
classes are in the same package, there is no recognizable difference between
access schemes protected, package, and public. Therefore, you can stick to using
just private and public.
In Sec. 3.5, we discussed the design of programs that contained classes. We
focused on the objects of the problem domain. We made a list of noun phrases
that described the objects that we thought the program would be manipulating,
and then we developed classes that would describe (some of) them. Some of the
verbs of the problem domain became methods of the classes.
In this section, we extend our notion of object-oriented design to include
The is-a relation
Consider designing a program to maintain a database of people associated with
a university. We start by constructing noun phrases for the objects that the pro-
gram will manipulate. What kind of people do we have? Well, there are grad stu-
dents, undergraduates, and non-degree students who are just taking a course.
There are professors, associate professors, and assistant professors. There are
secretaries, lab technicians, janitors, alumni, and so on.
Such a jumbled list of people is not easy to work with, so we organize them
into broad categories, such as student, faculty, staff, and alumni: