Mark As Completed Discussion

Polymorphism is a fundamental concept in Object-Oriented Programming (OOP). It allows us to perform a single operation in many ways and hence increases the modularity and readability of our code.

You might have come across financial derivatives in the financial market, right? These derivatives often have different underlying assets like stocks, bonds, commodities, etc., and they can be priced in many ways depending on their type and the nature of the underlying asset. Similarly, in OOP, polymorphism lets us define one interface (or method) and have multiple implementations.

Here's our game plan:

  • First, we'll define an interface - think of it as a contract that our objects are obliged to follow. Inherited classes (or subclasses) will need to implement these methods.

  • We'll then create a couple of classes that inherit from this interface. Each of these classes will have different implementations of the methods defined in the interface.

  • Finally, we'll use these objects interchangeably to demonstrate how we can achieve polymorphism.

CPP
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment