... variable is initialized to 0 in line 6. If a static variable is not initialized, the compiler assigns it a default value—in this case 0, the default value for type int.

Fig. 8.12

 1   // Fig. 8.12: Employee.java
 2   // static variable used to maintain a count of the number of
 3   // Employee objects in memory.
 4
 5   public class Employee {
 6      private static int count = 0; // number of Employees created
 7      private String firstName;
 8      private String lastName;
 9
10      // initialize Employee, add 1 to static count and
11      // output String indicating that constructor was called
12      public Employee(String firstName, String lastName) {
13         this.firstName = firstName;
14         this.lastName = lastName;
15
16         ++count; // increment static count of employees
17 System.out.printf( ...

Get Java How to Program, Early Objects, 11th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.