9.5 Creating References Using Inheritance Hierarchies

Enduring Understanding

When multiple classes contain common attributes and behaviors, programmers create a new class containing the shared attributes and behaviors forming a hierarchy. Modifications made at the highest level of the hierarchy apply to the subclasses.

Learning Objective

Define reference variables of a superclass to be assigned to an object of a subclass in the same hierarchy.

Essential Knowledge

When a class S “is-a” class T, T is referred to as a superclass, and S is referred to as a subclass.

If S is a subclass of T, then assigning an object of type S to a reference of type T facilitates polymorphism.

If S is a subclass of T, then a reference of type T can be used to refer to an object of type T or S.

Declaring references of type T, when S is a subclass of T, is useful in the following declarations:

§ Formal method parameters § arrays — T[] var ArrayList<T> var

Last updated

Was this helpful?