Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to introduce Class inheritance in OC

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

OC how to introduce class inheritance, many novices are not very clear about this, in order to help you solve this problem, the following small series will explain in detail for everyone, there are people who need this can learn, I hope you can gain something.

I haven't shared OC with you for a few days, so I have time to chat with you about OC grammar today. Are you interested?

Define a generic class with basic instance variables. Subclasses can inherit from this class, so they can own these instance variables. Then the corresponding subclass can also define its own instance variables.

Parent class (superclass): inherited class

Subclasses: Classes that inherit superclasses

The syntax rules inherited in OC are:

@interface subclass: parent class

ClassAB instance of overloaded ClassAB method

The initVar method in ClassB inherits from ClassA. You can also create a new method with the same name instead of the parent ClassA method

Condition: Define a new method with the same name, the new method must have the same return type, and the number of parameters is the same as the overloaded method

Control of authority

The default scope of instance variables is: within the class body. Instance variables inherited by default can be used directly.

Permission control symbols for instance variables default to projectedOC only supports single inheritance

Of course, we should put the common things in the parent class and the individual things in the child class.

Modifier class internal subclass anywhere

privateY

projectedYY

publicYYY

Methods are non-modifiable

But member variables can

@protected

@public

@private

Semicolons and colons are not allowed.

Define variables indented below modifiers

Dynamic Type: OC determines the actual type of an object at runtime

Dynamic binding: The program determines the actual method called by the object only at execution time

Polymorphic: The multiple states of a substance. Objects of different classes can define methods that share the same name. This is a form of polymorphism.

Polymorphic conditions: inheritance relationship, method overriding, declaration variable of parent class pointing to child object

Did reading the above help you? If you still want to have further understanding of related knowledge or read more related articles, please pay attention to the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report