我有一个内部类,我想从父类的静态方法中实例化如下:
public class MyClass {
public class B {
private int v;
B(int x) {
v = x;
}
public void pr() {
System.out.println(this.v);
}
}
public static void main(String args[]) {
int x=10;
int y=25;
int z=x+y;
B bb = new B(3);
System.out.println("Sum of x+y = " + z);
}
}
它抛出如下错误:
error: non-static variable this cannot be referenced from a static context
B bb = new B(3);
^
1 error