Java Reference
In-Depth Information
public class PayEmployees
{
public static void main(String [] args)
{
Salary s = new Salary(“Thomas Jefferson”, “Monticello, VA”,
3, 2600.00);
Hourly h = new Hourly(“John Adams”, “Boston, MA”, 2, 2.50);
h.setHoursWorked(40);
Contractor c = new Contractor(“M. Mouse”, “Anaheim, CA”,
44, 1000.00);
c.setDaysWorked(5);
SmartBoss boss = new SmartBoss();
boss.payEmployee(s);
boss.payEmployee(h);
boss.payEmployee(c);
}
}
Listing 8.17
The PayEmployees program instantiates and pays several types of employees.
Figure 8.7
The output of the PayEmployees program.
Lab 8.1: Using Polymorphism
The purpose of this lab is to become familiar with using polymorphism in
Java. You will use polymorphic parameters to write a class that can
“draw” any shape, and use virtual method invocation so that the appro-
priate shape is drawn without requiring any casting of references.
Search WWH ::




Custom Search