Objective C Polymorphism - Objective C

What is Polymorphism in Objective-C?

  • Polymorphism means having many forms.
  • Polymorphism occurs when there is a hierarchy of classes and they are related by inheritance.
  • In Objective-C polymorphism means a call to a member function that cause a different function that will be executed depending on the type of objects that invokes the function.

For Example, we have a class Shape that provides the basic interface for all the shapes. Square and Rectangle are derived from the base class Shape.
The method printArea that is going to show about the OOP feature polymorphism.

On compiling and executing the above code, the following result is produced:

Based on the availability of the method calculateArea and printArea, either the method in the base class or the derived class will be executed in the above example.

Polymorphism also handles the switching of methods between the base class and derived class based on the method implementation of the two classes.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Objective C Topics