Revision Notes
OxfordAQA A-Level Computer Science (9645): Relationships between classes – Revision Notes
Recall notes for OxfordAQA 9645 sub-topic 3.9.3: inheritance, base and subclasses, protected access, overriding, association, class diagrams and a self-test.
- Subject
- Computer Science
- Level
- A LEVEL
- Topic
- Topic 9 – Object-oriented and additional programming
- Author
- Marlbridge Academic Team
- Updated
- Reviewed by
- Harris Khan (what this means)
Aligned to OxfordAQA A Level Computer Science (9645), 2024-onwards. Official specification .
Syllabus page (what it covers and how it is assessed): OxfordAQA A Level Computer Science.
Syllabus points this page covers
9645 (A Level)
- 3.9.3 Relationships between classes
This page covers 1 of the 4 subtopics in topic 9, Object-oriented and additional programming.
Found an error? Report a correction.
Need help with this topic? Request a free trial class for A Level Computer Science (9645).
These notes condense sub-topic 3.9.3 Relationships between classes of OxfordAQA International AS and A-level Computer Science (9645), Version 1.1 (A-level content in topic 3.9 Object-oriented and additional programming). For explanations and examples, see the relationships between classes study guide; then practise with the relationships practice questions. Code is Python.
What the specification requires
- Know that inheritance makes one class a more specialised version of an existing class; create classes using inheritance.
- Know the base class (parent) and the subclass (derived class).
- Use the protected modifier so subclasses can access some members of the base class, but objects of other classes cannot.
- Know what overriding is and use it.
- Know that association is a relationship in which one object can make use of another, much weaker than inheritance; use it.
- Be familiar with class diagrams showing inheritance and association. Aggregation and composition need not be distinguished.
Key terms
| Term | Meaning |
|---|---|
| Inheritance | A subclass takes on the attributes and methods of a base class |
| Base class (parent) | The class being inherited from |
| Subclass (derived class) | The class that inherits and adds or changes behaviour |
| Protected | Accessible in the class and its subclasses |
| Overriding | Redefining a base class method in a subclass |
| Association | One object holding a reference to another object and using it |
super() |
Python’s way of reaching the base class (for the constructor, super().__init__(...)) |
| Virtual | In C# and VB.Net, a method must be declared virtual to be overridden |
Inheritance or association?
| Test | Inheritance | Association |
|---|---|---|
| Phrase | “is a kind of” | “uses” or “has” |
| Example | Teacher is a kind of Staff | Team uses Player objects |
| Strength | Strong | Weak |
| Python | class Teacher(Staff): |
An attribute that holds other objects (for example, a list) |
Inheritance pattern
class Staff:
def __init__(self, name, base_pay):
self.name = name
self._base_pay = base_pay # protected
def monthly_pay(self):
return self._base_pay
class Teacher(Staff):
def __init__(self, name, base_pay, subject):
super().__init__(name, base_pay) # set up inherited attributes
self.subject = subject
def monthly_pay(self): # overrides the base method
return self._base_pay + 200
Teacherinheritsnameand_base_pay, and everything else inStaff.Teacher("Rita", 2400, "Physics").monthly_pay()gives 2600.- A private (
__) attribute inStaffcannot be used by name insideTeacher.
Access in inheritance
| Member in base class | Subclass can use it? | Other classes? |
|---|---|---|
| Public (+) | Yes | Yes |
| Protected (#) | Yes | No |
| Private (−) | No | No |
Overriding
- The subclass redefines a method with the same name and parameters.
- An object of the subclass uses the redefined version, so it behaves differently from an object of the base class.
- A base class method that calls
self.method()uses the subclass’s version when the object is a subclass object. super().method()can call the base version from inside the overriding method.- In C# the base method must be
virtual; in VB.Net it must beOverridable.
Association pattern
class Team:
def __init__(self, title):
self.title = title
self.players = [] # holds references to Player objects
def add_player(self, player):
self.players.append(player)
def total_goals(self):
return sum(p.goals for p in self.players)
The same Player object can be referred to from more than one place. A change made to the player is seen by every object that refers to it.
Class diagram rules
- Each class is a box with name, attributes and methods.
- Access symbols: + public, − private, # protected.
- Inheritance: a line with a hollow triangle at the base class end.
- Association: a plain line.
- A subclass box lists only the members it adds or overrides.
Worked reminder: choosing relationships
A library has books, e-books and members. An e-book is a book with a file size. A member can borrow several books.
| Pair | Relationship | Reason |
|---|---|---|
EBook and Book |
Inheritance (Book is the base class) |
An e-book is a kind of book |
Library and Book |
Association | A library has a collection of books; it is not a kind of book |
Member and Book |
Association | A member uses books by borrowing them |
If EBook needs the title that Book stores, make the title protected in Book. If the base class reports a shelf location, EBook can override that method to say that the book is downloaded.
Worked reminder: overriding in action
class Account:
def withdraw(self, amount): # base version: always allowed
...
class SavingsAccount(Account):
def withdraw(self, amount): # override: checks a limit first
...
An Account object runs the first version and a SavingsAccount object runs the second, even though the method name is the same. Inside the override, super().withdraw(amount) can reuse the base class version once the checks have passed.
Reading a class diagram
- Find the hollow triangle. The class it touches is the base class.
- The classes at the other ends are subclasses.
- Read the symbols: + public, − private, # protected.
- A method that appears in both the base class and a subclass is overridden.
- A plain line between classes means association.
- Members listed only in the base class are inherited by the subclasses.
Exam traps
- Wrong relationship. Make Team a subclass of Player? No. Team uses Player.
- Forgot the base constructor. The inherited attributes are then missing.
- Private in a subclass. Private base members cannot be used by name; use protected.
- Not really overriding. The method name and parameters must match the base method.
- Triangle at the wrong end. The triangle touches the base class.
- Reversed class line.
class Staff(Teacher)makes Staff the subclass.
Quick self-test
- What does inheritance mean?
- What is another name for a base class?
- What is another name for a subclass?
- What does the protected modifier allow?
- What is overriding?
- What is association?
- Which phrase tests for inheritance?
- How does a Python subclass call its base class constructor?
- Which line type joins two classes in association on a class diagram?
- Where is the triangle drawn on an inheritance line?
- Why does a C# base method need
virtual? - Why is “a Team is a kind of Player” a poor use of inheritance?
Answers
- A subclass is a more specialised version of an existing class and takes on its attributes and methods.
- Parent class.
- Derived class.
- Access from the class and its subclasses, but not from objects of other classes.
- A method from the base class is redefined in a subclass so that subclass objects behave differently.
- A relationship in which one object can make use of another.
- “Is a kind of”.
super().__init__(...).- A plain line.
- At the base class end.
- So that a subclass is allowed to override it.
- A team is not a kind of player. A team uses players, so association is correct.
- Relationships between classes study guide
- Relationships between classes practice questions
- Additional programming revision notes
Official syllabus
OxfordAQA International AS and A-level Computer Science (9645) specification, Version 1.1, for International AS exams May/June 2025 onwards and International A-level exams May/June 2026 onwards: sub-topic 3.9.3 Relationships between classes.
Related resources
-
Study guides
OxfordAQA A-Level Computer Science (9645): Additional programming
OxfordAQA 9645 sub-topic 3.9.4 in depth: reading and writing text files, and recursion with base and recursive cases, traced step by step.
Computer Science · OxfordAQA · A Level
Read guide -
Practice questions
OxfordAQA A-Level Computer Science (9645): Additional programming – Practice Questions
Eleven original OxfordAQA 9645 questions on sub-topic 3.9.4: text files, recursion, base cases and traces, with full answers and verified output.
Computer Science · OxfordAQA · A Level
Try questions -
Revision notes
OxfordAQA A-Level Computer Science (9645): Additional programming – Revision Notes
Recall notes for OxfordAQA 9645 sub-topic 3.9.4: text file modes, reading and writing, recursion with base and recursive cases, traces and a self-test.
Computer Science · OxfordAQA · A Level
Revise topic
Get free revision emails (optional)
Occasional emails with practice questions, worked explanations and links to free resources for the qualification and subjects you choose. No spam, and you can unsubscribe from any email. The free tools on this site never need an email.