通过外部类可以访问难道内部类的私有成员

public class Outer {
  private int outProp = 8;
  class Inner {
    private int inProp = 5;
  }

  public void accessInnerProp() {
    System.out.println(new Inner().inProp);
  }

  public static void main(String[] args) {
    Outer p = new Outer();
    p.accessInnerProp();
  }
}

只是提示一下,外部类可以访问内部类的所有,只不过需要借助内部类对象

posted @ 2021-09-05 19:25  明月镇魂  阅读(188)  评论(0编辑  收藏  举报