Photo AI
Last Updated Sep 27, 2025
Revision notes with simplified explanations to understand Polymorphism (OOP) quickly and effectively.
477+ students studying
Polymorphism is a core concept in Object-Oriented Programming (OOP) that allows objects of different classes to be treated as instances of the same class, typically through a shared parent class. The term "polymorphism" means "many forms," and in programming, it enables a single function, method, or operator to work in different ways depending on the context. Polymorphism promotes flexibility, code reuse, and the ability to extend systems easily, as it allows programmers to write code that can uniformly handle different types of objects.
Example:
class Animal:
def make_sound(self):
return "Some generic animal sound"
class Dog(Animal):
def make_sound(self): # Overrides make_sound in Animal
return "Woof woof"
class Cat(Animal):
def make_sound(self): # Overrides make_sound in Animal
return "Meow"
# Using polymorphism
animals = [Dog(), Cat(), Animal()]
for animal in animals:
print(animal.make_sound())
Explanation: The make_sound method is overridden in both Dog and Cat, allowing each subclass to provide its own version of the method.
When the make_sound method is called on each object in the animals list, the correct method for each specific object (dog, cat, or generic animal) is executed.
class Calculator:
def add(self, a, b, c=0):
return a + b + c
calc = Calculator()
print(calc.add(3, 5)) # Outputs: 8
print(calc.add(3, 5, 10)) # Outputs: 18
Explanation: The add method in Calculator can accept two or three parameters.
This enables the same method to handle different types of input, even though Python achieves this without true overloading.
Example in Python (with an abstract base class):
from abc import ABC, abstractmethod
class Shape(ABC):
@abstractmethod
def area(self):
pass
class Rectangle(Shape):
def __init__(self, width, height):
self.width = width
self.height = height
def area(self): # Provides specific implementation
return self.width * self.height
class Circle(Shape):
def __init__(self, radius):
self.radius = radius
def area(self): # Provides specific implementation
return 3.14159 * self.radius ** 2
# Using polymorphism with an interface
shapes = [Rectangle(3, 4), Circle(5)]
for shape in shapes:
print(shape.area()) # Calls the area method for each shape
Explanation: Both Rectangle and Circle implement the area method defined by the Shape interface.
Each class provides its own version of area, which is called appropriately for each object in the shapes list.
Enhance your understanding with flashcards, quizzes, and exams—designed to help you grasp key concepts, reinforce learning, and master any topic with confidence!
70 flashcards
Flashcards on Polymorphism (OOP)
Revise key concepts with interactive flashcards.
Try Computer Science Flashcards7 quizzes
Quizzes on Polymorphism (OOP)
Test your knowledge with fun and engaging quizzes.
Try Computer Science Quizzes29 questions
Exam questions on Polymorphism (OOP)
Boost your confidence with real exam questions.
Try Computer Science Questions27 exams created
Exam Builder on Polymorphism (OOP)
Create custom exams across topics for better practice!
Try Computer Science exam builder12 papers
Past Papers on Polymorphism (OOP)
Practice past papers to reinforce exam experience.
Try Computer Science Past PapersDiscover More Revision Notes Related to Polymorphism (OOP) to Deepen Your Understanding and Improve Your Mastery
Join 500,000+ A-Level students using SimpleStudy...
Join Thousands of A-Level Students Using SimpleStudy to Learn Smarter, Stay Organized, and Boost Their Grades with Confidence!
Report Improved Results
Recommend to friends
Students Supported
Questions answered