package executionorder;
// initialization order:
// 1. static variable and static initialization blocks in which they are ordered.
// 3. instance variable and object initialization block in which they are ordered.
// 5. constructor
//"this" is initialized immediately after all static initialization has occurred (and before any instance variables are initialized)
//Static fields are initialized only once; static blocks executed only once
//NOTE: object initialization is called after all static methods are called and before constructor is called. There should be a constructor call.
public class InitializationBlock {
private static int nextId;
private int id;
private static String name;
int test = 10;
InitializationBlock a = this;
//object initialization block
{
id = nextId;
nextId++;
}
//static initialization block
static {
name = "Bikash Mainali";
}
InitializationBlock() {
System.out.println("constructor call");
}
static {
nextId = 1000;
}
public static void main(String[] args) {
new InitializationBlock();
}
}