Dark Horse programmer ---- Constructor

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.