Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: made compile failure explicit

...

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
bgColor#ccccff
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

...