Polymorphism
Discover the concept of polymorphism in object-oriented programming, learning how objects can take multiple forms with dynamic and static types. Understand method overriding for runtime behavior and method overloading plus operator overloading for compile-time polymorphism.
Introduction to polymorphism
The word polymorphism is a combination of two Greek words, “poly” meaning many, and “morph” meaning forms. In programming, polymorphism is a phenomenon that allows an object to have several different forms and behaviors.
For example, take the Animal class. There are many different animals, e.g., lion, deer, dog, and crocodile, etc. So, they are all animals, but their properties are different. The animal class can have a method, makeNoise. Its implementation should be different for a lion, deer, or any other animal as they all have different noises. This is called polymorphism.