(1)函數
程序以下:spa
1 public class Example { 2 static int i = 1, j = 2; 3 static { 4 display(i); 5 i = i + j; 6 } 7 8 static void display(int n) { 9 System.out.println(n); 10 } 11 12 public static void main(String[] args) { 13 display(i); 14 } 15 }
靜態的方法只能使用靜態的屬性code
從程序開始的時候優先執行static的方法,其次在執行main主函數blog