📄 Paper 1 · 4.1 Fundamentals of Programming
⭐ Pro
4.1.2c OOP — Inheritance, Polymorphism & Class Diagrams
AQA 7517 · A-Level Computer Science · ~20 min read

Inheritance

Inheritance allows a subclass (child class) to inherit the attributes and methods of a superclass (parent class). The subclass can then extend or override the inherited behaviour without rewriting common code.

Terminology: superclass / parent class / base class = the class being inherited from. Subclass / child class / derived class = the class that inherits.

AQA Pseudocode — Inheritance

CLASS Animal
    PRIVATE name : STRING
    PUBLIC PROCEDURE NEW(n : STRING)
        name ← n
    ENDPROCEDURE
    PUBLIC FUNCTION getName() RETURNS STRING
        RETURN name
    ENDFUNCTION
    PUBLIC PROCEDURE speak()
        OUTPUT "..."
    ENDPROCEDURE
ENDCLASS

CLASS Dog INHERITS Animal
    PRIVATE breed : STRING
    PUBLIC PROCEDURE NEW(n : STRING, b : STRING)
        CALL SUPER.NEW(n)   // Call parent constructor
        breed ← b
    ENDPROCEDURE
    PUBLIC PROCEDURE speak()   // Method override
        OUTPUT getName() & " barks!"
    ENDPROCEDURE
    PUBLIC FUNCTION getBreed() RETURNS STRING
        RETURN breed
    ENDFUNCTION
ENDCLASS

myDog ← NEW Dog("Rex", "Labrador")
CALL myDog.speak()    // Output: Rex barks!
OUTPUT myDog.getBreed()   // Output: Labrador

Benefits of Inheritance

  • Code reuse — subclasses don't repeat common code from the superclass
  • Extensibility — add new types by creating new subclasses
  • Hierarchical organisation — mirrors real-world "is-a" relationships (Dog IS-A Animal)
  • Maintainability — changes to common behaviour made in superclass automatically apply to all subclasses

Method Overriding

Method overriding occurs when a subclass provides its own implementation of a method that already exists in the superclass. The overridden version replaces the parent's version when called on a subclass object.

In the example above, Dog.speak() overrides Animal.speak().

Polymorphism

Polymorphism (meaning "many forms") allows objects of different classes to be treated as objects of a common superclass. The correct method is called at runtime based on the actual type of the object — not the variable's declared type.

This is most powerful when different subclasses override the same method — calling that method on each object produces different behaviour depending on the actual type.

// Both are Animals, but call different speak() implementations
a1 ← NEW Dog("Rex", "Lab")
a2 ← NEW Cat("Luna")   // Cat also INHERITS Animal with its own speak()
CALL a1.speak()    // Output: Rex barks!
CALL a2.speak()    // Output: Luna meows!

Benefits of Polymorphism

  • Write code that works with superclass type and automatically handles all subclasses
  • Reduces need for IF/CASE statements to check object type
  • Extends the system by adding new subclasses without changing existing code (open/closed principle)

Class Diagrams (UML)

A class diagram is a UML (Unified Modelling Language) diagram showing the structure of classes in an OOP system.

A class box shows three sections:

SectionContentsNotation
TopClass nameClassName
MiddleAttributes (with visibility and type)- name : String (- = private, + = public)
BottomMethods (with visibility, params, return type)+ getName() : String

Relationships in Class Diagrams

RelationshipArrowMeaning
InheritanceHollow arrowhead →IS-A: Dog inherits from Animal
AssociationPlain lineObjects use each other
AggregationHollow diamond ◇HAS-A (can exist independently)
CompositionFilled diamond ◆HAS-A (cannot exist without)
Exam tip: AQA A-Level questions on OOP often ask you to: write a subclass using INHERITS and SUPER.NEW(); explain what polymorphism means and why it is useful (typically 3–4 marks); draw or interpret a class diagram with inheritance shown using the correct arrow. Remember: IS-A = inheritance; HAS-A = association/composition.
⚠️ Common Mistakes
  • Forgetting to call SUPER.NEW() in the subclass constructor — needed to initialise parent attributes
  • Confusing overriding (subclass replaces a method) with overloading (same method name, different parameters — not in AQA scope)
  • Thinking polymorphism just means "different things" — specifically it means calling the same method name produces different behaviour depending on the object's actual type
  • Drawing the inheritance arrow the wrong way — arrow points FROM child TO parent
Click through the slides at your own pace. Use arrow keys or click to advance.
Click slide or press arrow keys to navigate

Worksheet — 4.1.2c OOP Inheritance, Polymorphism & Class Diagrams

8 questions · instantly marked · AQA 7517 standard

Q1Explain what inheritance is in OOP. Use the terms superclass and subclass in your answer.[3]
✅ Mark scheme
Mark scheme
Inheritance allows a subclass (child class) to receive/inherit the attributes and methods of a superclass (parent class) [1]; without rewriting the common code [1]; the subclass can also add new attributes/methods or override inherited methods [1].
Q2In AQA pseudocode, write the class header for a class called Cat that inherits from Animal. Include the constructor that calls the parent constructor and adds a private attribute colour.[4]
✅ Mark scheme
Mark scheme
CLASS Cat INHERITS Animal [1]; PRIVATE colour : STRING [1]; PUBLIC PROCEDURE NEW(n : STRING, c : STRING); CALL SUPER.NEW(n) [1]; colour ← c; ENDPROCEDURE [1].
Q3What is method overriding? Give an example using Animal and Dog classes.[3]
✅ Mark scheme
Mark scheme
Method overriding is when a subclass provides its own implementation of a method that already exists in the superclass [1]; the subclass version replaces the parent version when called on a subclass object [1]; e.g. Dog.speak() outputs "Rex barks!" whereas Animal.speak() outputs "..." [1].
Q4Explain what polymorphism means in OOP and why it is useful. Give one example.[4]
✅ Mark scheme
Mark scheme
Polymorphism means the same method name produces different behaviour depending on the actual type of the object at runtime [1]; it is useful because: code can work with superclass type and handle all subclasses automatically [1]; reduces need for IF/CASE to check object types [1]; example: calling speak() on a Dog gives "barks" and on a Cat gives "meows" — same method name, different implementation [1].
Q5Give three benefits of using inheritance in a large OOP system.[3]
✅ Mark scheme
Mark scheme
Any three: code reuse — no need to repeat common code [1]; extensibility — add new subclasses without modifying existing code [1]; hierarchical organisation mirrors real-world IS-A relationships [1]; maintainability — changes to superclass propagate to all subclasses [1].
Q6Describe the structure of a UML class diagram box, including what each of its three sections contains.[3]
✅ Mark scheme
Mark scheme
Top section: class name [1]; middle section: attributes with visibility symbols (- for private, + for public) and types [1]; bottom section: methods with visibility, parameter types, and return types [1].
Q7In a class diagram, what type of arrow is used to show inheritance? Which direction does it point?[2]
✅ Mark scheme
Mark scheme
A hollow (open) arrowhead [1]; pointing from the subclass (child) to the superclass (parent) [1].
Q8Why must a subclass constructor in AQA pseudocode call SUPER.NEW()? What happens if it doesn't?[2]
✅ Mark scheme
Mark scheme
SUPER.NEW() calls the parent class constructor to initialise the inherited attributes [1]; without it, the inherited attributes from the superclass would not be initialised, potentially causing errors when those attributes are accessed [1].
Topic Quiz
Question 1 of 15
You scored
out of 15
Card 1 of 12
Click to reveal definition
🎉
All cards reviewed!
TermDefinition
🎯

Mini Test — Inheritance & Polymorphism

10 questions · 10 minutes

← 4.1.2b OOP Classes & Encapsulation
10 of 70 · AQA 7517
4.2.1 Arrays, Records & ADTs →