In simple terms
A friendly intro before the formal notes — no formulas yet.
OOP's Powerful Trio
Inheritance, polymorphism, and abstraction are tools that let us build flexible and efficient code. They allow us to create a general 'blueprint' and then derive more specific, specialised versions from it.
Imagine you have a general blueprint for a 'Vehicle'. This blueprint states all vehicles must have a speed and a way to move. From this single blueprint, you can create more specific designs like a 'Car' (adding doors) or a 'Bicycle' (adding pedals). Inheritance is creating the specific designs from the general one. Polymorphism is the ability to treat a 'Car' and a 'Bicycle' both simply as 'Vehicles' in a list, yet when you tell each to 'move', they do so in their own unique way. Abstraction is the initial blueprint itself—it defines the essential features of a 'Vehicle' without getting bogged down in the specific details of how a car's engine or a bike's pedals work.
- 1
Define a general 'superclass' blueprint with common attributes and methods (e.g., a Person class).
- 2
Create specialised 'subclasses' that inherit these features and add their own (e.g., a Student class inherits from Person and adds a studentID).
- 3
Customise behaviour in subclasses by overriding methods from the superclass (e.g., a display() method shows different information for a Person and a Student).
- 4
Treat objects of different subclasses as if they are of the superclass type, allowing for flexible and dynamic code (e.g., an array of Person objects holding both Person and Student instances).
Explore the concept
Use the live diagram and synced steps — play it or tap a step card to walk through.
Full topic notes
Formal explanation with the rigour you need for the exam.
Inheritance: Building on Existing Code
Inheritance allows a new class, called a subclass or child class, to acquire the properties (attributes) and behaviours (methods) of an existing class, known as a superclass or parent class. This establishes an "is-a" relationship; for instance, a Car is a Vehicle. The subclass can then extend the functionality by adding new attributes and methods or modify existing behaviours.
// IB Pseudocode for Inheritance class SuperclassName // attributes and methods end class
class SubclassName extends SuperclassName // additional attributes and methods end class
Advantage: Code Reusability. Avoids duplicating code by placing common functionality in a superclass.
Advantage: Extensibility. New features can be added in a subclass without modifying the superclass.
Disadvantage: Tight Coupling. Subclasses are tightly bound to their superclass's implementation. Changes to the superclass can break subclasses.
UML Representation: A solid line with a hollow arrowhead points from the subclass to the superclass.
Polymorphism: One Interface, Many Implementations
Polymorphism allows objects of different classes to be treated as objects of a common superclass. A key mechanism for this is method overriding, where a subclass provides its own implementation of a method that it inherited from its superclass. This means you can call the same method on different objects and get different, specialised behaviour depending on the object's actual class.
Be careful not to confuse method overriding (polymorphism) with method overloading. Overloading involves multiple methods in the same class with the same name but different parameters. Overriding involves a method in a subclass with the exact same signature as a method in its superclass. Exam questions often test this distinction.
Abstraction: Focusing on the Essentials
Abstraction is the process of hiding implementation details from the user and only providing functionality. In OOP, this is often achieved with abstract classes and abstract methods. An abstract class is a blueprint that cannot be instantiated itself. It can define abstract methods—methods without any implementation—which act as a contract, forcing any non-abstract subclass to provide an implementation for them. This ensures that all subclasses have a certain set of behaviours, even if the implementation of those behaviours differs.
Purpose: To hide complexity and define a contract for subclasses.
Abstract Class: Cannot be instantiated. Designed to be inherited.
Abstract Method: A method declared without an implementation. Must be overridden by any concrete (non-abstract) subclass.
Advantage: Enforces a common structure across a family of classes, promoting consistency and reducing errors.
Advantage: Simplifies the understanding of complex systems by focusing on what an object does, not how it does it.
In a design question (often in Paper 2), justifying the use of an abstract class is a high-level skill. You can argue for it when you have a general concept (like Shape or Account) that doesn't make sense to create an object of directly, but you want to enforce common methods (like getArea() or deposit()) in all its specific subclasses (Circle, SavingsAccount).
Worked examples
See the formulas applied — reveal one step at a time, like the exam.
A software system models different types of media. A MediaItem has a title (String) and duration in seconds (integer). A Song is a type of MediaItem that also has an artist (String).
(a) Using IB-style pseudocode, declare the MediaItem class with a constructor. [2] (b) Declare the Song class, which inherits from MediaItem. It should have a constructor that initialises all three attributes. [3]
- 1
Mark Scheme & Solution
Continuing from the previous example, a PodcastEpisode class also extends MediaItem and has a host attribute. Both Song and PodcastEpisode need a display() method. For a Song, it should output "Title by Artist". For a PodcastEpisode, it should output "Title hosted by Host".
An array myPlaylist is created as follows:
Trace the output of the following code snippet:
loop for item in myPlaylist
item.display()
end loop
- 1
Iteration 1: item refers to the Song object. The display() method from the Song class is executed.
How it all connects
The big idea sits in the middle — tap a linked idea to explore the link.
Tap a linked idea to see how it connects back to the main topic — that connection is what examiners reward.
Glossary
Try to recall each definition before you reveal it.
Quick check
Answer in your head first — then tap to check. No pressure.
Revision flashcards
Flip the card. Test yourself before the exam.
What is inheritance in OOP?
A mechanism where a new class (subclass or child class) derives attributes and methods from an existing class (superclass or parent class). It represents an "is-a" relationship.
Key takeaways
Review these before you close the topic — retrieval beats re-reading.
- ✓
Advantage: Code Reusability. Avoids duplicating code by placing common functionality in a superclass.
- ✓
Advantage: Extensibility. New features can be added in a subclass without modifying the superclass.
- ✓
Disadvantage: Tight Coupling. Subclasses are tightly bound to their superclass's implementation. Changes to the superclass can break subclasses.
- ✓
UML Representation: A solid line with a hollow arrowhead points from the subclass to the superclass.
Practice — then mark it
The whole point: a real Cambridge question, marked mark-by-mark.
Practice Exam Questions
Practice Exam Questions
Extra simulations & links
PhET, GeoGebra and other curated tools — open in a new tab.
Frequently asked
Checkpoint
One marked question is worth ten re-reads — close the loop before you move on.
Reading it isn’t knowing it — prove it.
Before you move on: do Practice Exam Questions on paper, snap a photo, and get examiner-style feedback on exactly where you win and lose marks.