Our next program declares two classes—
Employee (Fig. F.12) and
EmployeeTest (Fig. F.13). Class
private static variable
count (Fig. F.12, line 9) and
public static method
getCount (lines 36–39). The
count is initialized to zero in line 9. If a
static variable is not initialized, the compiler assigns it a default value—in this case
0, the default value for type
count maintains a count of the number of objects of class
Employee that have been created so far.
1 // Fig. F.12: Employee.java 2 // Static variable used to maintain a count of the number of 3 // Employee objects in memory. 4 5 ...