Java The Complete Reference, Seventh Edition

(Greg DeLong) #1

Chapter 2: An Overview of Java 19


Inheritance interacts with encapsulation as well. If a given class encapsulates some
attributes, thenany subclass will have the same attributesplusany that it adds as part of its
specialization (see Figure 2-2). This is a key concept that lets object-oriented programs grow
in complexity linearly rather than geometrically. Anew subclass inherits all of theattributes
of all of its ancestors. It does not have unpredictable interactions with the majorityof the rest
of the code in the system.


Polymorphism
Polymorphism(from Greek, meaning “many forms”) is a feature that allows one interface to
be used for a general class of actions. The specific action is determined by the exact nature


FIGURE 2-2 Labrador inherits the encapsulation of all its superclasses

Free download pdf