OC Base notes--self and Super (Guangzhou Black Horse first phase)

Source: Internet
Author: User

Local variables, member variables, and global variables
1. Inside a method, you can define a local variable with the same name as the member variable.
So within the scope of this local variable, he overrides the member variable.
2, if the definition and member variables with the same name as local variables, but also (ˇ?ˇ) want to manipulate local variables;
3, global variables, the entire file sharing, all methods shared;
A method that modifies this global variable in other ways uses this global variable to modify

4. There is a principle in the scope of variables: the nearest principle
Lookup order local variable-"member variable-" global variable

Self and Method
1. Self in the object method, it is the object that calls this method
2, self in the class method represents the class, he can call other class methods

Summarize:
Who calls this method then self is who

intAgenew = -;@implementationCzperson-(void) Changeage: (int) age{//_age =;//    ////int _age = ten;//    //    //agenew = +;//    //_age = age;//    //self->_age = age;[Self setage: -];}- (void) Setage: (int) age{NSLog (@"Setage"); _age=Age ;}- (int) age{NSLog (@"agenew =%d", agenew); return_age;}+ (int) Sumofnum: (int) Num Andother: (int) other{returnNum +Other ;}+ (int) Averageofnum: (int) Num Andother: (int) other{return[Self sumofnum:num andother:other]/2;}@end

OC Base notes--self and Super (Guangzhou Black Horse first phase)

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.