Field initializers and instance initializer blocks run in textual order as the object is built, and all of them finish before the constructor's own body executes.
class Widget {
int a = log("field a");
{
log("instance initializer");
}
int b = log("field b");
Widget() {
log("constructor");
}
static int log(String msg) {
System.out.println("Running: " + msg);
return 0;
}
}
new Widget();
Running: field a
Running: instance initializer
Running: field b
Running: constructor
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-09-27