1. constructor 1. constructor: the method used to initialize an object. It is an object method starting with-. 2. purpose of rewriting constructor: to create an object, the member variable will have some fixed values; 3. you can create an object in either of the following ways:
4. Override constructor: 1. First call the constructor of the parent class: [Super init]; 2. initialize the member variables in the subclass.
Ii. Custom constructor 1. Specifications of custom constructor:
- It must be an object method and must start;
- The return value is generally of the ID type;
- The method name generally starts with initwith;
2. Sample codes and notes for custom constructor:
- Parent class (person. h) file:
- Parent class (person. m) File
- Subclass (student. h) file:
- Subclass (student. m) file:
- Main. M file:
- Running result:
Dark Horse programmer ---- Constructor