[ ]
.
class Outer {
private static int x = 0;
class Inner {
void print() {
System.out.println(x);
}
}
public static void main(String[] args) {
new Outer().new Inner().print();
}
}
Even the Outer class can access any field of the Inner class, but through an object of the inner class.
class Outer {
private class Inner {
private int x = 10;
}
void print() {
Inner inner = new Inner();
System.out.println(inner.x);
}
public static void main(String[] args) {
Outer outer = new Outer();
outer.print();
}
}
source
share