public class EnclosingClass{
public void enclosingClassMethod(){
InnerClass iC = new InnerClass();
ic.innerClassPrivateMethod(); // this one works but why the following line doesn't //work
InnerClass.innerClassPrivateMethod(); // Why I can't call the method like this?
}
public class InnerClass{
private void innerClassPrivateMethod(){
}
}
}
Why we can't call the innerClassPrivateMethod()
like InnerClass.innerClassPrivateMethod()
? I see "Cannot make a static reference to the non-static method innerClassPrivateMethod()
from the type EnclosingClass"
If I change both the innerClassPrivateMethod
and enclosingClassMethod
as private I get error for
InnerClass iC = new InnerClass();
as "No enclosing instance of type Basics6 is accessible. Must qualify the allocation with an enclosing instance of type enclosingClass."