1  import java.util.Scanner;
  2  
  3  /**
  4     This program demonstrates polymorphism by applying a method
  5     to objects of different classes.
  6  */
  7  public class SalaryDemo
  8  {
  9     public static void main(String[] args)
 10     {
 11        Employee[] staff = new Employee[3];
 12        staff[0] = new HourlyEmployee("Morgan, Harry", 30);
 13        staff[1] = new SalariedEmployee("Lin, Sally", 52000); 
 14        staff[2] = new Manager("Smith, Mary", 104000, 50);
 15        
 16        Scanner in = new Scanner(System.in);
 17        for (Employee e : staff)
 18        {
 19           System.out.print("Hours worked by " + e.getName() + ": ");
 20           int hours = in.nextInt();
 21           System.out.println("Salary: " + e.weeklyPay(hours));
 22        }
 23     }
 24  }