OC Basic Notes-Inheritance (Guangzhou black horse Phase I)

Source: Internet
Author: User

The inheritance mechanism in OC is single-inheritance, and a subclass can have only one parent class
OC supports multilayer inheritance, a inherits Nsobject,b inheritance A which is called multi-layer inheritance

The order of method calls in the inheritance system

1. Find in your own class
2, if not, go to the parent class to find
3, if not in the parent class, go to the parent class
4, if the parent class also does not have, it also looked up until the base class (NSObject) was found
5, if NSObject did not have an error

Only inherit nsobject so this object has the ability to create objects
NSObject is the base class for most classes (root Class),
/*
When Class A inherits Class B, then class A has all the member variables and methods in class B
1. Inheritance Benefits: Code Reuse
2, Inheritance disadvantage: The change of the parent class affects all the subclasses, the child class and the parent class coupling degree is very high

Class A inherits Class B for the purpose of using member variables and methods in class B
Usage scenarios:
When we find that a class is another class, we can use inheritance, such as the student is a person, then when defining the student class, we can let the students inherit the human


3, when the subclass does not want to use the parent class method, then the parent class method overrides

OC Basic Notes-Inheritance (Guangzhou black horse Phase I)

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.