We know that objects of inner classes can only arise from objects of the enclosing class. So then why is it the case that an object of a inner class cannot invoke a non-static method of an enclosing class outside the definition of the enclosing class?
public class OuterClass
{
public class InnerClass
{
public void innerMethodA()
{
outerMethodA(); // This is OK.
new InnerClass().outerMethodA(); // This is not OK.
}
}
public void outerMethodA()
{
System.out.println("This is OuterMethodA");
}
}
public class ExtraClass
{
public void testMethod()
{
OuterClass outerObj = new OuterClass();
OuterClass.InnerClass innerObj = outerObj.new InnerClass();
outerObj.outerMethodA(); // This is OK.
innerObj.outerMethodA(); // This is not. Why is that?
}
}
Please excuse any mistakes in formatting or the way I am putting forward my question. I edited it after some down votes. I tried my best. Thank you.