Java Reference
In-Depth Information
Display 8.6
Employee Class and Its Derived Classes (part 1 of 2)
These show the details needed for the current discussion. You
should not need to review the entire class definitions from Chapter 7.
Complete definitions of all these classes are given in the subdirectory
for this chapter on the website that comes with this text.
1 public class Employee
2 {
3
The class Date is defined in Display 4.13, but the
details are not important to the current
discussion. There is no need to review the definition
of the class Date.
private String name;
4
private Date hireDate;
5
public Employee()
The body of the constructor is given in Display 7.2 should initialize the
instance variables, but the details are not needed for this discussion.
6
public boolean equals(Object otherObject)
The body of the method equals is the same as in Display 7.10, but the details of the definition are not
important to the current discussion.
All other constructor and other method definitions are exactly the same as in Display 7.2.
The class Employee has no method named getPay .
7 }
1 public class SalariedEmployee extends Employee
2 {
3
private double salary; //annual
4 /**
5 Returns the pay for the month .
6 */
7 public double getPay()
8 {
9
return salary / 12;
10 }
11
public boolean equals(Object otherObject)
The rest of the definition of equals is the same as in the answer to Self-Test Exercise 20 of Chapter 7,
but the details of the definition are not important to the current discussion.
All constructor and other method definitions are exactly the same as in Display 7.5.
12 }
(continued)
 
Search WWH ::




Custom Search