我正要创建一个类,其他类的Java:内部类的访问级别
public class Sq {
class Inner {
private int a; //no getters setters
//a is private
private Inner (int a1) {
this.a = a1;
}
}
public static void main(String[] args) {
Sq outter = new Sq();
Inner d = outter.new Inner(3);
System.out.println("Private a = " + d.a);
}
}
它的工作原理里面..所以,我可以访问内部的私人领域,也是我添加Inner2类,并试图改变“一”从Inner2而且还曾:/
所以看起来像在内部类私人没有那么私人,看起来像它的公共在W内孔类。
所以嵌套类中的所有字段和方法都是公用的外部? – Ihor
是的!这就像他们是外部类的一部分,像'私人诠释号码'... – Marcx
哦,我看到了,非常感谢你 – Ihor