public class Test { public int aMethod(){ static int i = 0; // 编译失败, 静态变量只能在类主体中定义,不能在方法中定义 i++; return i; } public static void main(String args[]){ Test test = new Test(); test.aMethod(); int j = test.aMethod(); System.out.println(j); } }
转载于:https://my.oschina.net/u/3847203/blog/3014593