Sun Guoqiao's Mock Exam No.2 ex. no. 9
public class Test009
{
public static void main(
String args[])
{
Test009.Inner inner1=new Test009().new Inner(); //1
Inner inner2=new Test009().new Inner(); //2
inner2.method(); //3
Noninner ninr=new Noninner();// This has been added by me
//ninr.methodA(); //4 This has been added by me
}
class Inner
{
private void method()
{
System.out.println("0");
}
}
}
// This portion has been added by me
class Noninner{
private void methodA()
{
System.out.println("10");
}
}
____________________________________________________________________
My Doubt:-
The method invocation at //3 works fine even though it calls a private method of inner class in other class (Here it is the enclosing outer class.).
The method invocation at //4 (commented out) causes the expected compile time error due to invocation of private method in other class.
Why this ambiguity? Does it mean that any method( having any access modifier), defined within an inner class is also visible in the Outer/enclosing class?
Please Clarify?
Thanks in advance,
Raj Shah