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.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.