7.3. Field Defaults and Field Initializers

Local variables do not have a default value. They cannot be used until they are initialized. By contrast, class fields are automatically initialized to the default values for their types. As you may recall from Chapter 3, fields are set to 0 or null or false by default, depending on their type. It is a good idea, however, to set your instance fields to something you can use and not just leave them with their defaults.

As you might imagine, initializing a class field value looks like this:

public int i = 3; 
public static boolean b = true;

The syntax here is useful if you want to have all of a class's constructors set your instance field to the same value. You can initialize objects through initialization ...

Get Java™ for ColdFusion® Developers 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.