One of the most important concepts in object-oriented programming is that of inheritance.
What is the inheritance
Inheritance allows us to define a class in terms of another class which makes it easier to create and maintain an application.
Features of using inheritance
- Reuse the code functionality and fast implementation time.
Base & Derived Classes:
- In inheritance theexisting class is called the base class
- The new class is referred to as the derived class.
Note : Objective-C allows only multilevel inheritance, i.e., it can have only one base class but allows multilevel inheritance. All classes in Objective-C is derived from the superclass NSObject.
@interface derived-class: base-class
Access Control and Inheritance:
- A derived class can access all the private members of its base class if it’s defined in the interface class
- but it cannot access private members that are defined in the implementation file.
A derived class inherits all base class methods and variables with the following exceptions:
- Variables declared in implementation file with the help of extensions is not accessible.
- Methods declared in implementation file with the help of extensions is not accessible.
- In case the inherited class implements the method in base class, then the method in derived class is executed.