為什么外部Java類可以訪問內(nèi)部類私有成員?我注意到,外部類可以訪問內(nèi)部類、私有實(shí)例變量。這怎麼可能?下面是演示相同的示例代碼: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??
}}為什么允許這種行為?
為什么外部Java類可以訪問內(nèi)部類私有成員?
ibeautiful
2019-07-08 16:43:46