@public members can be arbitrarily assigned, you should use the Set method and the Get method to manage access to members
A) Set method
1. Function: Provide a method to set the value of member variables to the outside world, can be in the method to face the parameters of the corresponding filter
2. Naming conventions:
1> method name must begin with set
2> set followed by the name of the member variable, the first letter of the member variable must be capitalized
3> return value must be void
4> must receive a parameter, and the parameter type is consistent with the member variable type
The name of the 5> parameter cannot be the same as the member variable name
II) Get method
Get method
1. Function: Returns the member variable inside the object
2. Naming conventions:
1> must have a return value, and the return value type must be the same as the member variable type
The 2> method name is the same as the member variable name
3> does not need to receive any parameters
c) member variable naming specification
The member variable must begin with an underscore _
Effect: 1. To separate the name of the member variable from the Get method
2. Can be separated from the local variables, a see the beginning of the underscore variable, is usually a member variable
IV) Practice
Design a grade class
* C language Score (readable and writable)
* OC result (readable and writable)
* Total score (read only)
* Average score (read only)
Analysis: Readable and writable are both set and get methods to write
Read-only is write-only get method
Write your own code as follows
Dark Horse Programmer--oc Language Set method and get method