The big idea: Polymorphism means the same call does the right thing for whatever object it is made on.
Shapes: Calling area() on a list of shapes gives each shape's own calculation. The calling code never asks what kind of shape it holds.
class Shape:
def area(self):
raise NotImplementedError
class Circle(Shape):
def area(self):
return 3.14159 * self.r ** 2
class Rectangle(Shape):
def area(self):
return self.w * self.h
for s in [Circle(2), Rectangle(3, 4)]:
print(s.area()) # each object runs ITS OWN versionabstract class Shape {
abstract double area();
}
class Circle extends Shape {
double r;
@Override double area() {
return 3.14159 * this.r * this.r;
}
}
class Rectangle extends Shape {
double w, h;
@Override double area() {
return this.w * this.h;
}
}
for (Shape s : new Shape[]{ new Circle(2), new Rectangle(3, 4) }) {
System.out.println(s.area()); // each object runs ITS OWN version
}The loop never asks what it is holding: No if isinstance and no type check anywhere. The object itself decides which method runs, which is the whole point — and why a new shape needs no change to this loop.
Free preview
This is the free notes preview
You're reading the free notes. Aimnova Pro unlocks the full study experience — and you can try it with your first topic free to keep:
- FlashcardsLock in vocabulary and key terms with spaced repetition.
- Practice questionsAnswer exam-style questions and get instant AI marking.
- Mock exams & past-paper vaultSit full mocks and see exactly how examiners award marks.
- Personalised study planA daily plan built around your exam date and weak areas.
| Overriding | Overloading | |
|---|---|---|
| Also called | Run-time (dynamic) polymorphism | Compile-time (static) polymorphism |
| Same method name in | Parent and child | One class |
| Differs by | Which class the object is | The parameters supplied |
| Decided | When the program runs | When it is compiled |
| Example | Circle.area() against Rectangle.area() | add(int, int) against add(double, double) |
These are routinely confused: Overriding replaces a parent's method in a child — same signature, different class. Overloading defines several methods with the same name and different parameters in the same class.
An answer that swaps them loses the mark even when the example is right.
Static polymorphism in Python: Python has no true overloading: a second method with the same name replaces the first. The same effect comes from default parameters, e.g. def area(self, w, h=None). Java chooses between overloaded methods at compile time, which costs nothing when the program runs.
Learn what examiners really want
See exactly what to write to score full marks. Our AI shows you model answers and the key phrases examiners look for.
Code that does not change
- A new subclass works with existing loops immediately
- No if-chain to extend, so no chance of forgetting one
- Adding behaviour without editing working code
One interface
- Callers learn one method name, not one per type
- The calling code reads as what it wants, not how each type does it
The alternative
- Without it: a long if the type is Circle … otherwise if it is Rectangle chain
- Every new type means editing every such chain
- And every one you miss is a silent bug
Name what it replaces: The strongest polymorphism answer says what the code would look like without it: a type-checking if-chain that must be found and extended everywhere a new type is added.
How this is tested — you must show the same call behaving differently AND explain what it saves. It comes up two ways:
Paper 2 — working with code
- Explain polymorphism, 3-4 marks
- Distinguish overriding from overloading
- State what a given call outputs
Paper 2 — the algorithmic-thinking question
- Construct classes demonstrating it
- Explain why it removes a type-checking chain
The classic trap: Describing inheritance and calling it polymorphism. Inheritance is sharing a method; polymorphism is the same call resolving differently per object. Show two different outputs from one line of code.
One unchanged call line reaching a different method as the object changes.
Interactive diagram
Explore the labelled diagram, charts and maps for this topic in full study mode.
A payments system handles CardPayment, BankTransfer and VoucherPayment, each processed differently. Explain how polymorphism lets one loop process a mixed list, and what it saves.
Model answer plan
See the answer broken into clear points, with guidance on how each point earns marks.