As some sources say, the Java instance initialization blocks are executed whenever instance is created or right before constructor. But imagine this case:
public
No. The initialization blocks are copied directly into the constructor(s). Obviously there is an implicit super in there as well. So your example becomes
public class Foo {
public Foo()
{
{System.out.println("Foo init");} // initializer.
{System.out.println("Foo constr");}
}
}
public class Main extends Foo {
public Main()
{
super(); // super constructor.
{System.out.println("Main init");} // initializer.
{System.out.println("Main constr");}
}
public static void main(String[] args) {
new Main();
}
}
Which explains your observed behavior of
Foo init
Foo constr
Main init
Main constr