The difference between object methods and class methods

Source: Internet
Author: User

Class method

1. Calls to class methods are not dependent on the object and are called directly with the class name [class name Method name]

2. Class method Syntax: + (return value type) method name

3. A class method cannot access a member variable of a class object

4. Object methods can also be called in class methods

5. In general, when you do not access class member variables, you use class methods, which are typically tool classes

6. Use class methods to improve performance and efficiency

Object methods

1. Invocation of the object method depends on the object [object pointer method name]

2. Object method Syntax:-(void) method name

3. The member variables of the class object can be accessed in the object method

Note: Two object methods and class methods with the same name can be used in the same class

Example:-(void) test and + (void) test

The difference between object methods and class 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.