Java中靜態變量只能是成員變量,局部方法中的局部變量除final外不能有任何其他修飾符,例如:
1 public class Test { 2 static String x = "1"; 3 static int y = 1; 4 5 public static void main(String args[]) { 6 static int z = 2; //報錯,無論是普通局部方法還是靜態局部方法,內部的局部變量都不能有修飾符 7 8 System.out.println(x + y + z); 9 } 10 11 public static void get(){ 12 final int m = 2; 13 // m = 3; //報錯,final修飾的基本類型不可變,String類型不可變,引用類型的引用地址不可改變,但是引用中的內容是可變的 14 final Student s = new Student("1", "abc", 12); 15 Student s2 = new Student("1", "abc", 12); 16 // s = s2; //報錯 17 s.setAge(13); 18 } 19 }