静的および非静的のメソッドとフィールドを試しています。私はこれをコンパイルしようとしました:
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」はどちらも静的ではありません。