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

expert

Which is the best of GCD, NSThread or NSOperationQueue ?

middle

What is the purpose of managed object context NSManagedObjectContext in Objective-C and how does it work?

expert

Explain the use case when ARC won't help you to release memory (but GC will)

Bình luận

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

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