Java Reference
In-Depth Information
//***************************************************************
// File name: SimpleInherit.java
// Reference: Chapter 16
//***************************************************************
// Topics:
// 1. Simple inheritance
// 2. Polymorphism by method overriding
//**********************************************************
//**********************************************************
//******************************************
//******************************************
// Employee class
//******************************************
//******************************************
class Employee
{
//********************************
// attributes section
//********************************
// Instance fields
private String name;
private String address;
private String ssn;
private int dependants;
private int number;
// Class attribute (note the static qualifier)
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.dependants = x;
this.number = ++consecNum; // class attribute is accessed
// from an object method
}
public void showData()
{
System.out.print("number: " + this.number);
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\tdependants: " + this.dependants +
"\n\n");
System.out.flush();
}
Search WWH ::




Custom Search