我发现外部类可以访问内部类的私有实例变量。这是如何实现的?以下是演示此功能的示例代码:
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??
}
}
为什么允许这种行为?
new ABC().new XYZ()
。 - Josh M.