public class Demo1 { static { test = 1; // System.out.println(test); } static int test; public static void main(String[] args) { System.out.println("Hello World!"); } }
其实上面的代码,编译器会自动编译为:
1 2 3 4 5 6 7 8 9 10 11
import java.io.PrintStream; public class Demo1 { static int test = 1; public static void main(String[] args) { System.out.println("Hello World!"); } }