我正在尝试静态和非静态方法和字段。我试图编译这个:
class main{
public int a=10;
static int b=0;
public static void main(String[] args){
b+=1; //here i can do anything with static fields.
}
}
class bla {
void nn(){
main.a+=1; //why here not? the method is non-static and the field "main.a" too. Why?
}
}
编译器返回我:
try.java:10: non-static variable a cannot be referenced from a static context
但为什么?方法和字段“a”都是非静态的!