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

前端 未结 9 2164
我寻月下人不归
我寻月下人不归 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:18

    You need to probably put public static void main(String[] args){ } method in your class for JDK7. In JDK7, main method's presence is checked before the static block and if it doesn't find one you get the exception.

提交回复
热议问题