class abc {
int a = 0;
static int b;
static abc h = new abc(); //line 4
public abc() {
System.out.println("cons");
}
{
System.out.println("ini");
}
static {
System.out.println("stat");
}
}
public class ques {
public static void main(String[] args) {
System.out.println(new abc().a);
}
}
When i wrote this code I am getting output in order like this:
ini
cons
stat
ini
cons
0
Here when I created a new object in main(), class abc
got loaded and static
variables and blocks are executed in order they are written. When control came to line 4 static abc h = new abc();
Instance Initialization block is called. Why? why is static block not called when a new object is created at line 4 and till that time static block was also not called even once, so according to convention static block should have been called. Why is this unexpected output coming?