Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Protected accessibility is illegal for top-level classes; nested classes may be declared protected. Fields of non-final public classes should rarely be declared protected; untrusted code in another package can subclass the class and access the member. Furthermore, protected members are part of the API of the class and, thus, require continued support. When this guideline is followed, there is no need to declare a field as protected. The guideline OBJ00OBJ01-J. Declare data members as private and provide accessible wrapper methods recommends declaring fields as private.

...

In this noncompliant code example, the class Point is declared public. Even though this example complies with guideline OBJ00OBJ01-J. Declare data members as private and provide accessible wrapper methods, untrusted code could instantiate Point and invoke the public getPoint() to obtain the coordinates.

...