What is object field initialization and constructor order in Java

Yes, in Java (unlike C#, for example) field initializers are called after the superclass constructor. Which means that any overridden method calls from the constructor will be called before the field initializers are executed.

The ordering is:

  • Initialize superclass (recursively invoke these steps)
  • Execute field initializers
  • Execute constructor body (after any constructor chaining, which has already taken place in step 1)

Basically, it’s a bad idea to call non-final methods in constructors. If you’re going to do so, document it very clearly so that anyone overriding the method knows that the method will be called before the field initializers (or constructor body) are executed.

See JLS section 12.5 for more details.

Leave a Comment