Declaration and implementation of object methods

Source: Internet
Author: User

1. Declaration of object Methods

Format:

1 -(int) ADDNUM1: (int) NUM1 andNum2: (int) num2;

2. Features

A: Object method with-opening as-(int) xx;

B: Object methods can only be called by objects

C: The member variable of the current object can be accessed in the object method

D: Call format [Object Name object method name];

3. Example

1 //declares an object method that does not return a value2-(void) run;3 //object methods that declare a return value4-(int) run;5 //An object method that declares a parameter with a return value6-(int) Run: (int) num;7 //object method that declares a return value with multiple arguments8-(int) Run: (intNum and: (int) time;

4. The object method is to implement

a:必须写在以@implementation开头,@end之间b:在声明的后面加上{}即表示实现c:将需要实现的代码写在{}中

Declaration and implementation of object methods

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.