改成:
public class test2 { static void test_static() {
int i = 0;
System.out.println( i );
} public static void main( String[] args ) {
//test a = new test();
test2.test_static(); }
}
public class test2 { static void test_static() {
int i = 0;
System.out.println( i );
} public static void main( String[] args ) {
//test a = new test();
test2.test_static(); }
}
static int i;这句不能存在于方法体中的,放到方法体以外去。
//为什么静态方法体内不能定义静态变量,这一点有点怪....谢了(kaymo).....
---------------------------------------------静态方法体和一般方法体中的语句没有什么本质区别啊。方法中的变量(也叫本地变量(local variable))只存在于方法体中,方法体结束就被回收了,当然不能定义成static,方法中的变量只能有一种修饰符,就是final。还有,方法中的变量没有默认值,也就是说它不会自动初始化,使用前必须显式地赋值。