The difference and connection between Object-c and instance methods

Source: Internet
Author: User

When I was studying OC, I always had no idea when to use the class method, when I used the instance method. So I made the following summary.

-Represents an instance method: Access by instance method

+ Represents a class method: An object of a class method when the class is not an instance. More for creating objects or tool classes

When to use a class method, to create an instance to get a shared instance, or to get some common information about the class.

1. The class method belongs to the entire class, not to an object.

2. Class methods can access only class member variables, cannot access instance variables, and instance methods access class member variables and instance variables.

3. The invocation of a class method can be done through the class name. class methods and objects. Class methods, and instance methods can only be accessed through the object. Instance method.

4. Class methods can only access class methods, and instance methods have access to class methods and instance methods.

5, the class method cannot be overwritten, the instance method can be overwritten.

The difference and connection between Object-c and instance 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.