aımnova
DashboardMy LearningCrash CoursesStudy Plan

Aimnova site navigation

Stay in the loop

Get the latest study resources and updates

New features, study tips and exam insights — straight to your inbox.

IB Diploma

  • IB Past Papers
  • IB Study Notes
  • IB Question Bank
  • IB Mock Exams
  • IB Revision

IB Subjects

  • IB Math AA
  • IB Math AI
  • IB Economics
  • IB Business Management
  • IB Physics
  • IB Biology
  • View all IB subjects→

IB Past Papers

  • IB Math AA HL Past Papers
  • IB Math AA SL Past Papers
  • IB Math AI HL Past Papers
  • IB Math AI SL Past Papers
  • IB Economics HL Past Papers
  • IB Economics SL Past Papers
  • IB ESS Past Papers
  • View all past papers→

Study Resources

  • Study Notes
  • Question Bank
  • Mock Exams
  • Crash Courses
  • Flashcards
  • Revision Guide
  • Exam Skills
  • Command Terms
  • Grade Calculator
  • Exam Timetable 2026

Aimnova

  • Features
  • Pricing
  • For Teachers
  • For Schools
  • For Parents
  • About Us
  • Blog
  • Contact
aımnova

IB study, practice and feedback built around the real exam.

TermsPrivacyCookies·© 2026 Aimnova. All rights reserved.c1e448f

Aimnova is not affiliated with or endorsed by the International Baccalaureate Organization (IB).

NotesComputer Science HLTopic 7.2Inheritance
Back to Computer Science HL Topics
7.2.15 min read

Inheritance (Computer Science HL)

IB Computer Science · Unit 7

Smart study tools

Turn reading into results

Move beyond passive notes. Answer exam-style questions, get AI feedback, and build the skills that earn top marks.

Get Started Free

Contents

  1. 1Define once, specialise after
  2. 2The is-a test
  3. 3Overriding, and how deep to go
  4. 4Exam-style question
The big idea: Inheritance lets one class be defined as a specialised version of another. The child gets the parent's attributes and methods without repeating them, and adds what makes it different.

Write it once, change it in one place.
class Account:
    def __init__(self, owner, balance):
        self.owner = owner
        self._balance = balance

    def deposit(self, amount):
        if amount > 0:
            self._balance += amount

class SavingsAccount(Account):      # inherits everything above
    def __init__(self, owner, balance, rate):
        super().__init__(owner, balance)   # reuse the parent's setup
        self.rate = rate

    def add_interest(self):             # the specialisation
        self.deposit(self._balance * self.rate)
class Account {
    String owner;
    protected double balance;

    Account(String owner, double balance) {
        this.owner = owner;
        this.balance = balance;
    }

    void deposit(double amount) {
        if (amount > 0) {
            this.balance += amount;
        }
    }
}

class SavingsAccount extends Account {   // inherits everything above
    double rate;

    SavingsAccount(String owner, double balance, double rate) {
        super(owner, balance);           // reuse the parent's setup
        this.rate = rate;
    }

    void addInterest() {                 // the specialisation
        this.deposit(this.balance * this.rate);
    }
}
super() is not optional politeness: The parent's constructor is what sets the inherited attributes. Skip super().__init__ and the object exists with those attributes missing — a fault that appears far later, wherever one is first read.

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.
Start Studying Free Full access to Aimnova Pro · cancel anytime
Inheritance (is-a)Composition (has-a)
Reads asA SavingsAccount is an AccountA Car has an Engine
Child getsEverything the parent hasOnly what it asks the part to do
Change the parentEvery child is affectedOnly the direct user
Use whenThe child genuinely is a kind of the parentOne thing is built from another

What a child class can reach in its parent

Parent member isJava: can the child use it directly?Python
publicYes, and so can every other classNormal names, e.g. self.owner
protectedYes, and so can classes in the same packageBy convention one underscore, e.g. self._balance: "for this class and its children"
default (no modifier)Only if the child is in the same packageNo equivalent
privateNo: it is inherited but hidden; the child must use the parent's public or protected methods (e.g. a getter)Two underscores, e.g. self.__pin, is renamed so a child cannot reach it by that name
Say the sentence out loud: "A Car is an Engine" is absurd, so inheritance is wrong there. "A SavingsAccount is an Account" is true, so it is right.

Inheriting for convenience — because a class happens to have methods you want — produces a hierarchy nobody can reason about.

What inheritance actually buys

  • Shared attributes defined once, so they cannot drift apart
  • A change to shared behaviour is one edit, not one per subclass
  • Children can be treated as the parent wherever the parent is expected
  • New kinds can be added without touching existing code

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.

Try AI Feedback FreeYour first topic is free to keep • No credit card required
1

Override

A child can redefine a parent method. Its version is used for objects of that class; the parent's is untouched for everything else.

2

Extend rather than replace

Call the parent's version with super() and add to it, rather than copying its code into the child. Copied code is code that will diverge.

3

Keep hierarchies shallow

Three levels deep and finding where a method is actually defined becomes a search. Depth is a cost paid on every read of the code.

4

Protected, not private

A child cannot see the parent's private members. Attributes the child must reach are marked protected instead.

Inheritance is the tightest coupling there is: A child depends on the parent's internals, not just its interface. Changing the parent can break every subclass at once — which is why "prefer composition" is common advice, and why the is-a test matters.

How this is tested — you must justify inheritance with the is-a test AND with what duplication would cost. It comes up two ways:

Paper 2 — working with code

  • Explain inheritance and its purpose, 3-4 marks
  • Identify the parent class in a scenario
  • State what a child inherits

Paper 2 — the algorithmic-thinking question

  • Design a hierarchy and justify it
  • Explain why inheritance is wrong for a given pair
The classic trap: Naming the parent class and stopping. The marks are for why: the is-a relationship holds, and the shared attributes would otherwise be defined twice and drift apart.
IB-style questionConstruct[5 marks]

A library system handles Books and DVDs. Both have a title, an ID and a loan status; a Book also has an author and page count, a DVD a duration and certificate. Construct a class design and justify the use of inheritance.

Model answer plan

See the answer broken into clear points, with guidance on how each point earns marks.

Claim your free topic

Try an IB Exam Question — Free AI Feedback

Test yourself on Inheritance. Write your answer and get instant AI feedback — just like a real IB examiner.

In a game, the parent class Character keeps its health value private. A child class Wizard needs to read the health. the effect of the private modifier and how Wizard can still read the value. [2 marks]

Related Computer Science HL Topics

Continue learning with these related topics from the same unit:

7.1.1Fundamentals of OOP7.1.2Designing classes7.1.3Static vs non-static7.1.4Classes and objects
View all Computer Science HL topics
Improve your exam techniqueCommand terms, paper structure, and mark-scheme tips for Computer Science HL
Previous7.1.5EncapsulationNextPolymorphism7.2.2

11 exam-style questions ready for you

Students who practice on Aimnova improve their scores by 15% on average. Get instant feedback that shows exactly how to improve your answers.

Practice Now — FreeView All Computer Science HL Topics