8.2. Initializers

Initializers can be employed for initialization of fields in objects and classes, resulting in the fields being assigned initial values. These initializers are

  • field initializer expressions

  • static initializer blocks

  • instance initializer blocks

The rest of this section provides details on these initializers, concluding with a discussion on the phases involved in constructing the state of an object, when the object is created by using the new operator.

Field Initializer Expressions

Initialization of fields can be explicitly specified in field declaration statements using initializer expressions. The value of the initializer expression must be assignment compatible to the declared field (see Section 3.4, p. 47 and Section 6.6, p. ...

Get Programmer's Guide to Java™ Certification, A: A Comprehensive Primer, Second 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.