interface A{
int x=0;
}
class B{
int x=1;
}
class C extends B implements A{
static int x=2;
public void pX(final int x){
//int x=3;
System.out.println(x);
} public static void main(String[] args){
new C().pX(super.x);
}
}
Cannot use super in a static context , 为什么?
int x=0;
}
class B{
int x=1;
}
class C extends B implements A{
static int x=2;
public void pX(final int x){
//int x=3;
System.out.println(x);
} public static void main(String[] args){
new C().pX(super.x);
}
}
Cannot use super in a static context , 为什么?
比如类A又静态方法f和非静态方法g,那么调用f可以直接
A.f();
而调用g则必须:
A a;
a.f();
从简单的角度说,“静态方法不能调用非静态成员”这是Java语法规定的,违反语法的事当然编译器不会允许的。
void f1(){}
}public class B extends A{
void f2(){super.f1();}
}