... 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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.