The visible field of the access modifier
Private-the member is accessible only from the top-level class where it is declared.
Package-private-the member is accessible from any class in the package
where it is declared. Technically known as default access, this is the access level
You get if no access modifier is specified.
Protected-the member is accessible from subclasses of the class where it is
Declared (subject to a few restrictions [JLS, 6.6.2]) and from any class in the
Package where it is declared.
Public-the member is accessible from anywhere.
Instance fields should never is public, so classes and public mutable fields is not Thread-safe
It's wrong for a class
To has a public static final array field, or an accessor that returns such a
Field. If A class has such a field or accessor, clients'll be is able to modify the contents
of the array. This is a frequent source of security holes:
Potential security hole!
public static final thing[] VALUES = {...};
Beware of the fact that many IDEs generate accessors so return references to private
Array fields, resulting in exactly this problem. There is ways to fix the
Problem. You can make the public array private and add a public immutable list:
private static final thing[] Private_values = {...};
public static final thing[] values () {
return Private_values.clone ();
}
Effective Java English Second Edition reading notes Item 13:minimize the accessibility of classes and members