Why can the private member of an nested class be accessed by the methods of the enclosing class?
本问题已经有最佳答案,请猛点这里访问。
有人能告诉我关于私有成员的访问级别吗?很长时间以来,我一直对这段代码感到困惑:为什么在outer类的"print"方法中可以访问line类的私有成员k?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
这些规则在JLS的无障碍章节中。
Otherwise, if the member or constructor is declared
private , then
access is permitted if and only if it occurs within the body of the
top level class (§7.6) that encloses the declaration of the member or
constructor.
这里,成员字段
关于顶级课程的章节在这里。