Java Reference
In-Depth Information
private String name = "no name";
private String address;
private String ssn = "xxx";
private int dependants = 1;
// Default for dependants field
private int empNum;
// Class attribute (static qualifier)
private static int empCounter = 0;
The class contains five fields and one class variable. The field variables
are related to the objects of the class. The class variable named
empCounter is used to keep track of the total number of objects created.
Thus, the class-level variable allows the program to keep track of how
many employees are in the payroll and assigns a consecutive number to
each new employee. The class variable is associated with the class, not
with objects. In this case the class variable keeps track of the consecutive
number of the employee objects.
Search WWH ::




Custom Search