I have written a simple class with one static block
class Hello
{
static {
System.out.println(\"Hello\");
System.exit(0);
}
}
Upto JDK1.6:-
It first load the class and while loading the class static block will be executed. and then check the main method to execute.
JDK1.7 onwards :
It checks main method first whether it is available or not.
if available
then first execute static and
then main method will be executed.
if not available
throw error