... relationship between subclasses and superclasses (i.e., the is-a relationship) by assigning a subclass reference to a superclass variable. This program uses classes CommissionEmployee and BasePlusCommissionEmployee from Fig. 9.10 and Fig. 9.11, respectively.

Fig. 10.1 Assigning superclass and subclass references to superclass and subclass variables.


 1   // Fig. 10.1: PolymorphismTest.java
 2   // Assigning superclass and subclass references to superclass and
 3   // subclass variables.
 4
 5   public class PolymorphismTest {
 6      public static void main(String[] args) {
 7         // assign superclass reference to superclass variable            
 8         CommissionEmployee commissionEmployee = new CommissionEmployee(  
 9            "Sue", "Jones", "222-22-2222", 10000, .06);                   
10
11         // assign subclass reference ...

Get Java How To Program, Late Objects, 11th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.