Câu hỏi phỏng vấn Objective-C
Câu hỏi

What is the difference between inheritance and Categories in Objective-C?

Câu trả lời

The main differences between inheritance and categories in Objective-C are:

Inheritance allows a class to inherit properties and methods from a superclass, creating a hierarchical relationship between classes[1][3]. A subclass inherits all the instance variables and methods from its superclass, and can add new methods or override inherited ones[1][3]. Objective-C supports single inheritance, where a class can have only one superclass[1].

Categories, on the other hand, allow adding methods to an existing class at runtime, without subclassing[2]. Categories are used to extend the functionality of a class by adding new methods, or even overriding existing methods[2]. Unlike inheritance, categories do not inherit instance variables from the class they extend[2]. Categories are commonly used to add functionality to system classes like NSString...

middle

middle

Gợi ý câu hỏi phỏng vấn

middle

When to use NSArray vs NSSet ?

junior

What are blocks and how are they used?

expert

What is Dynamic Dispatch and how does it work in Objective-C?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào