June 2017
Beginner
1296 pages
69h 23m
English
... 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.
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 to subclass variable
12 BasePlusCommissionEmployee basePlusCommissionEmployee = ...