Polymorphism

Last updated

What is Polymorphism?

Polymorphism is a concept in object-oriented programming (OOP) that allows objects of different classes to be treated as objects of a common parent class. This is achieved by defining a common interface for all classes that need to be treated polymorphically. The word polymorphism is derived from Greek, "poly" means many and "morph" means form.

There are two types of polymorphism:

  • Compile-time polymorphism (also called static polymorphism or early binding) occurs when the type of the object that is going to be acted upon is determined at compile-time. This is achieved through method overloading, which allows multiple methods to have the same name but different parameters within the same class.
  • Run-time polymorphism (also called dynamic polymorphism or late binding) occurs when the type of the object is determined at run-time. This is achieved through method overriding, which allows a child class to provide a specific implementation of a method that is already defined in its parent class.

Free resources to learn Polymorphism

More in stage 4: Design Principles

Polymorphism: common questions

Can I learn Polymorphism in Hindi?

This lesson is written in English. Once you sign in, open it in the interactive course and ask the AI tutor to explain Polymorphism in Hindi or Hinglish. The tutor answers from this lesson’s own text, so it stays on the syllabus, and it runs on your own Google, OpenAI or Anthropic key.

Is this Polymorphism tutorial for beginners?

It is lesson 31 of 94 in the free Software Design and Architecture roadmap, in stage 4, Design Principles. If you are new to Software Design and Architecture, start from stage 1 and come back here in order; if you already know the earlier stages, this lesson stands on its own.

Still confused? Ask me