Objective-c one of three major features: inheritance

Source: Internet
Author: User

One, inherit the syntax form:
@interface Class Name: Parent class name

Second, the main points of inheritance grammar:
1, the inherited class is called the parent class or superclass, and the inherited class is called a subclass.
2, basically all classes inherit from NSObject (base class).
3, the subclass inherits all the member variables and methods in the parent class and the parent class of the parent class.
4, the name of the member variable in the parent class and subclass cannot be the same, otherwise it will be an error.
5, the parent class and the subclass of the method name can be the same, when the subclass has the same method or method in the parent class implementation, when the subclass calls this method, the system will first call the subclass of the same name method. This practice is called rewriting.
6, in the override of the Super keyword can be called directly in the parent class method, mainly used when the subclass extends the parent class method. The Super and Self keywords are similar in other usages.


Third, the advantages of inheriting the syntax:
1, avoids duplication of code.
2, the connection between classes and classes can be established.

Four, the disadvantage of inheritance syntax:
1, enhance the coupling of the program, when the parent class is changed or deleted, it will seriously affect the operation of the subclass.

I summarize myself, if there are mistakes, please correct me, thank you.

Objective-c one of three major features: inheritance

Related Article

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.