/**
* 外部类可以访问内部类的私有成员
*/
package test;
public class Test{
int a =1;
private static class inner{
private static Test t = new Test();
private static int b = 2;
}
private class inner2{
//private static int c = 2;//不能声明为static,因为inner2只有 new Test时才分配内存??
private int c = 3;
}
public static void main(String[] args) throws Exception {
int x = Test.inner.t.a;
System.out.println(x);
System.out.println(Test.inner.b);
//int y = new inner2().c;//error
Test ty = new Test();
int y = (ty.new inner2()).c;
System.out.println(y);
}
}
外部类可以访问内部类的私有成员
最新推荐文章于 2022-09-02 23:49:09 发布