In this chapter, let's talk about why you need access rights?
1. Because it solves a problem: to separate unchanging and often changing
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, id this domain is often based on the operation of constant changes, and the method get and set are basically fixed down, so the ID is private, and the Get, set method is public
2. Solve the contradiction between front and back programmers
Most of the time the backend program needs to be modified, while the front end relies on the output of the backend, so the front end often opposes back-end modifications.
With access control, you can solve this problem.
From the above code we can see, as long as the method name, the same as the return value, the same parameters, the front-end developers only need to call, and then how to modify the backend does not matter.
3. By introducing the package, you can put classes of the same function unit together to avoid erroneous calls elsewhere.
Summary: This section briefly discusses the three reasons why you need access rights.
This chapter is here, thank you.
-----------------------------------
Directory
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Get to know java-5.1 from scratch Why do I need access rights?