Java Reference
In-Depth Information
public class Salary extends Employee
{
private double salary; //Annual salary
public Salary(String name, String address, int number,
double salary)
{
super(name, address, number);
setSalary(salary);
}
public double getSalary()
{
return salary;
}
public void setSalary(double newSalary)
{
if(newSalary >= 0.0)
{
salary = newSalary;
}
}
public double computePay()
{
System.out.println(“Computing salary pay for “ + getName());
return salary/52;
}
}
Listing 8.2
The Salary class extends the Employee class.
Now, let's look at a couple of statements that might be familiar to you.
Suppose that we instantiated an Employee object as follows:
Employee e = new Employee(“George W. Bush”, “Houston, TX”, 43);
The previous statement creates two entities in memory: the Employee refer-
ence e, and the Employee object to which the e gets assigned. The reference is
of type Employee, and so is the object it refers to.
Similarly, the following statement is valid:
Salary s = new Salary(“George Washington”, “Valley Forge, DE”, 1, 5000.00);
In this statement, s is a Salary reference, and it is assigned to a new Salary
object. Both the reference and the object are of type Salary.
Search WWH ::




Custom Search