January 2014
Intermediate to advanced
736 pages
70h 43m
English
Our next program declares two classes—Employee (Fig. F.12) and EmployeeTest (Fig. F.13). Class Employee declares private static variable count (Fig. F.12, line 9) and public static method getCount (lines 36–39). The static variable 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 int. Variable 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 ...
Read now
Unlock full access