Static block is not executing in JDK 7, “Main method not found”, but works in JDK 1.5

前端 未结 9 2166
我寻月下人不归
我寻月下人不归 2021-01-07 20:19

I have written a simple class with one static block

class Hello
{

  static {
           System.out.println(\"Hello\");
       System.exit(0);
     }
}
         


        
9条回答
  •  情书的邮戳
    2021-01-07 21:13

    Yes, in jdk7. Static blocks are not first executed. It looks first for the entry point in the application.

    So, it first checks for public static void main(String a[]) , if this method is not present, static block will not be executed.

提交回复
热议问题