I am new to Java.
My file is A.javaas follows:
public class A {
public class B {
int k;
public B(int a) { k=a; }
}
B sth;
public A(B b) { sth = b; }
}
In another java file, I'm trying to create an object A that calls
anotherMethod(new A(new A.B(5)));
but for some reason I get an error: No enclosing instance of type A is accessible. Must qualify the allocation with an enclosing instance of type A (e.g. x.new B() where x is an instance of A).
Can someone explain how I can do what I want? I really want to instantiate Aand then install it sthand then pass the instance to the Amethod, or is there any other way to do this?
source
share