public class TestLab {
static Test aStatic=new Test();
public static void main(String[] args) {
TestLab obj=new TestLab();
}
static{
System.out.println("In static block of TestLab");
}
}
public class Test {
static Test ref=new Test();
Test()
{
System.out.println("Default Constructor of Test");
}
static
{
System.out.println("In Static Block of Test");
}
{
System.out.println("In instance block of Test");
}
}
Normally the static blocks are executed first during class loading. When the above example is executed, the following output is received:
In instance block of Test
Default Constructor of Test
In Static Block of Test
In instance block of Test
Default Constructor of Test
In static block of TestLab
Why does the instance block and Default Constructor of Test class gets executed before the static block of Test Class?