I have an inner class, which I want to instantiate from the static method of the parent class as follows:
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);
}
}
It is throwing an error as follows:
error: non-static variable this cannot be referenced from a static context
B bb = new B(3);
^
1 error