外部类可以访问内部类的私有成员

来源:互联网 发布:数据备份常用的方式 编辑:程序博客网 时间:2024/03/29 14:29
/** * 外部类可以访问内部类的私有成员 */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;//errorTest ty = new Test();int y = (ty.new inner2()).c;System.out.println(y);} }  

原创粉丝点击