Java Reference
In-Depth Information
}
public void mailCheck()
{
System.out.println(“Mailing a check to “ + this.name
+ “ “ + this.address);
}
public String toString()
{
return name + “ “ + address + “ “ + number;
}
public String getName()
{
return name;
}
public String getAddress()
{
return address;
}
public void setAddress(String newAddress)
{
address = newAddress;
}
public int getNumber()
{
return number;
}
}
Listing 8.1
(continued)
The Salary class, shown in Listing 8.2, has one field named salary to repre-
sent the annual pay of an employee. The Salary class also has one constructor,
a computePay() method, and various accessor and mutator methods. The idea
behind this design is that not every Employee has a salary, so adding a salary
field in the Employee class would cause issues later; therefore, the child classes
of Employee will contain the fields and methods needed to compute the
employee's pay. Later in this chapter, we will define the Hourly class that also
extends Employee, and it will have fields for an hourly wage and number of
hours worked, as well as a computePay() method.
Search WWH ::




Custom Search