Java Reference
In-Depth Information
System.out.print("\thours: " + this.hoursWorked + "\n\n");
}
} // End of class HourlyEmployee
//******************************************
//******************************************
// Driving class
//******************************************
//******************************************
public class ObjectArray
{
//******************************
// data
//******************************
// Define an array of type Employee with 4 elements
static Employee[] empArray = new Employee[4];
static int objType;
// Object type
//*****************************
// methods
//*****************************
public static void main(String[] args)
{
// Create two objects of Employee class
Employee emp1 = new Employee("Jane", "131 Calm Street",
"263", 2);
Employee emp2 = new Employee("Jim", "42 Curve Road",
"261", 6);
// Create an object of the class HourlyEmployee
HourlyEmployee emp3 =
new HourlyEmployee ("Jack", "11 Bumpy St.", "333",
8, 11.00, 40);
// Fill the array of objects of type Employee with objects of
// the superclass and the subclass.
empArray[0] = emp1;
empArray[1] = emp2;
empArray[2] = emp3;
// This is an object of the subclass
// The next object is entered from the keyboard.
// The user first selects the object's class
objType = Keyin.inInt("Type 0 for superclass or 1 for " +
"subclass: ");
// Insert object in array according to user's input
if(objType == 0)
empArray[3] = new Employee("Lori", "222 Dumb Street",
"333", 7);
else
empArray[3] = new HourlyEmployee ("Joe", "11 End St.",
"999", 8, 11.00, 40);
Search WWH ::




Custom Search