参照することはできません与えられたコードです:私はこれらのエラーを取得していますJavaエラー:非静的変数は、ここでは、静的な文脈から
class Super {
protected int n;
Super(int n){
this.n=n;
}
public void print(){
System.out.println("n="+n);
}
}
class Sub {
Sub(int m){
Super.n=m;
}
}
class Test{
public static void main(String[] args){
Sub s= new Sub(10);
s.print();
}
}
:
Main.java:19: error: non-static variable n cannot be referenced from a static context
Super.n=m;
...........^
Main.java:25: error: cannot find symbol
s.print();
誰かが、なぜこれらを教えてくださいすることができエラーが発生しますか?
を意味しましたか? – templatetypedef
私はこれに答えましたが、これが単にタイプミスではない理由がない限り、それをタイプミスとしてフラグを立てるつもりです。 – Ares