我观察到外类可以访问内部类私有实例变量.这怎么可能?以下是演示相同内容的示例代码:
class ABC{
class XYZ{
private int x=10;
}
public static void main(String... args){
ABC.XYZ xx = new ABC().new XYZ();
System.out.println("Hello :: "+xx.x); ///Why is this allowed??
}
}
Run Code Online (Sandbox Code Playgroud)
为什么允许这种行为?