G.10.6. Polymorphic Processing, Operator instanceof and Downcasting
To test our
Employee hierarchy, the application in Fig. G.21 creates an object of each of the four concrete classes
BasePlusCommissionEmployee. The program manipulates these objects nonpolymorphically, via variables of each object’s own type, then polymorphically, using an array of
Employee variables. While processing the objects polymorphically, the program increases the base salary of each
BasePlusCommissionEmployee by 10%—this requires determining the object’s type at execution time. Finally, the program polymorphically determines and outputs the type of each object in the
Employee array. Lines 9–18 create objects of ...