private变量引用问题
1 public class Scope{ 2 private int i; 3 public static void main(String argv[]){ //注意main参数不能少,否则编译ok,运行抛出异常!可以为String argv[]或String[] argv或String [] argv 4 Scope s = new Scope(); 5 s.amethod(); 6 }//End of main 7 public static void amethod(){ 8 System.out.println(i); 9 }//end of amethod 10 }//End of class
编译报错,无法在静态方法中引用非静态变量。

注意:顶层(非嵌套)类不能是私有的。
浙公网安备 33010602011771号