1.4 如何在main()方法之前执行输出“hello world”
public class Test{ static{ System.out.println("hello world"); } public static void main(String[]args){ } }
不管static的位置在哪,静态块的执行都是在main()方法之前。
public class Test{ static{ System.out.println("hello world"); } public static void main(String[]args){ } }
不管static的位置在哪,静态块的执行都是在main()方法之前。