I am searching for a long time on net. But no use. Please help or try to give some ideas how to achieve this?why the result is not to print the "int main"in the first? What I want to know is why the result of this program is as follow?Thanks in advance.
super static block
static block 4
in main
super constructor
constructor
class StaticSuper {
static {
System.out.println("super static block");
}
StaticSuper() {
System.out.println("super constructor");
}
}
public class StaticTests extends StaticSuper {
static int rand;
//static initialise
static {
rand = (int) (Math.random() * 6);
System.out.println("static block " + rand);
}
StaticTests() {
System.out.println("constructor");
}
public static void main(String[] args) {
System.out.println("in main");
StaticTests st = new StaticTests();
}
}