...
Use the private
access specifier for declaring the inner class(es) and all contained methods and constructors. The compiler will refuse to compile AnotherClass
because of its attempt to access a private nested class.
Code Block | ||
---|---|---|
| ||
class Coordinates {
private int x;
private int y;
private class Point {
private void getPoint() {
System.out.println("(" + x + "," + y + ")");
}
}
}
class AnotherClass {
public static void main(String[] args) {
Coordinates c = new Coordinates();
Coordinates.Point p = c.new Point(); // fails to compile
p.getPoint();
}
}
|
Risk Assessment
...