Java Reference
In-Depth Information
Invoking the computePay() methods on the Salary and Hourly objects gen-
erates the following output:
Paying employees
Computing salary pay for Jane Smith
2 1923.0769
Computing hourly pay for George Washington
3 550.0
Notice that the Employee object referenced by e in the InheritDemo
program cannot invoke the computePay() method because the object
does not have a computePay() method. In fact, there is no place to put
information about how or what Robert Smith is paid. It is safe to say
that no employee at the company will want to be of type Employee.
This does not mean that the Employee class is not useful. In fact, the
opposite is true. Even though we will not be needing objects of type
Employee, the Employee class plays a fundamental and essential role
in the design of our program.
The mailCheck() method is available to all three objects in the InheritDemo
program. Invoking them causes the following output:
Mailing checks
Mailing a check to Robert Smith 111 Java Street
Mailing a check to Jane Smith 222 Oak Drive
Mailing a check to George Washington 333 Espresso Lane
The entire output of the InheritDemo program is shown in Figure 6.1.
The bytecode for Employee, Salary, Hourly, and InheritDemo all need to be
in the same folder on your hard drive. Putting the bytecode in the same
folder is necessary for the compiler and the JVM to find these files, at
least until you become familiar with CLASSPATH, discussed in Chapter 7,
“Advanced Java Language Concepts.”
Figure 6.1
Output of the InheritDemo program.
Search WWH ::




Custom Search