O'Reilly logo

Programmer's Guide to Java™ Certification, A: A Comprehensive Primer, Second Edition by Rolf W. Rasmussen, Khalid A. Mughal

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required