Why access permissions are required for java-5.1 from the ground up?
In this section, let's talk about why access permissions are required?
1. because it solves the problem of separating the constant and the constant changes
Package com. ray. ch05; public class Test {private int id = 0; public int getId () {return id;} public void setId (int id) {this. id = id ;}}
From the code above, we can see that the attribute field id often changes constantly according to the operation, and the methods get and set are basically fixed, so id is private, the get and set methods are public.
2. Resolve conflicts between front-end programmers
Most of the time, the backend program needs to be modified, and the front-end is often opposed to the backend modification because it depends on the back-end output.
You can solve this problem through access control.
Through the code above, we can see that as long as the method name is the same, the return value is the same, and the parameters are the same, the front-end developer only needs to call it, and then it doesn't matter how the backend modifies it.
3. Introduce package to put classes of the same function unit together to avoid calling errors elsewhere.
Summary: This chapter briefly discusses three reasons for access permissions.