Java Reference
In-Depth Information
private static int consecNum = 0;
//*********************************
// methods section - constructors
//*********************************
// Fully parameterized constructor for Employee objects
public Employee(String n, String a, String s, int x)
{
this.name = n;
this.address = a;
this.ssn = s;
this.dependents = x;
this.empNum = ++consecNum; // class attribute is accessed
// from an object method
}
public void showData()
{
System.out.print("number: " + this.empNum);
System.out.print("\tname: " + this.name);
System.out.print("\t\taddress: " + this.address);
System.out.print("\n\t\tSSN: " + this.ssn);
System.out.print("\t\tdependents: " + this.dependents +
"\n\n");
System.out.flush();
}
} // end of class Employee
class HourlyEmployee extends Employee
{
//********************************
// attributes section
//********************************
private double hourlyWage;
private int hoursWorked;
//*********************************
// methods section
//*********************************
// Constructor
public HourlyEmployee(String n, String a, String s, int x,
double wage, int hours)
{
// Call the constructor in the superclass
super(n, a, s, x);
// Initialize specific fields
this.hourlyWage = wage;
this.hoursWorked = hours;
}
public void showData()
{
super.showData();
System.out.print("wage: " + this.hourlyWage);
Search WWH ::




Custom Search