2_Objective-C Inheritance

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.

Syntax

@interface derived-class: base-class

Example

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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: