12th minimizing the accessibility of classes and members
In a sense, we should try to limit the access of members to the smallest extent possible! For decoupling, development, testing, and optimization can be more independent.
For members (domains, methods, nested classes, and nested interfaces), there are four possible access levels, ranging from small to large:
1. Private, only the inside of the class that declares the member can access
2. Package-level private, any class within the package that declares the member's class can be accessed if the member does not display the declared access level, which is the level, so it becomes the default access level
3.protected, the class that declares the member and its subclasses can access, and any class in the package that declares the class can also access
4.public, any class can access
In addition, constants in Java are globally accessible, public static final integer values_integer = new Integer (10);
The Values_integer above is immutable, and the public static final array can be changed:
Public classMaintestjava { Public Static FinalInteger Max_num =NewInteger (10); Public Static FinalInteger[] Max_num_a = {NewInteger (10),NewInteger (10),NewInteger (10)}; /** * @paramargs*/ Public Static voidMain (string[] args) {//TODO auto-generated Method StubInteger II =NewInteger (11); max_num_a[1] = II;//no errors, can be assignedMax_num = II;//There is an error, you cannot assign a value }}
So you can use the static final method of public to get the clone of the array, set the Max_num_a to private, and not change
[Effective Java Reading notes] Chapter III class and interface 12th