我观察到外部类可以访问内部类的私有实例变量。这怎麽可能?下面是一个示例代码,演示了这一点:
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??
}
}
为什么允许此行为?
https://stackoverflow.com/questions/1801718
复制相似问题