Programming with Objects

OOP Pseudocode

Part 5 of the Paper 4 OOP chapter — the same OOP you write in Python, expressed in 9618 Cambridge pseudocode: CLASS/ENDCLASS, the NEW constructor, INHERITS and SUPER, method overriding and polymorphism. Mark schemes are written in pseudocode, so even if you code in Python you must read and write pseudocode classes fluently. Exactly as the Pseudocode Guide defines them.

25.1 Introduction: OOP in Cambridge Pseudocode

In Paper 4 you write real Python (or Java or VB.NET), but in Paper 3 and in mark schemes the language is Cambridge pseudocode. The OOP ideas are identical to the ones you already know — only the keywords change. Methods are PROCEDURE/FUNCTION; the constructor is NEW; inheritance uses INHERITS; the parent is reached with SUPER.

This page mirrors the Python chapter in pseudocode. By the end you can write a class with methods, a constructor, an inheriting subclass that calls SUPER, and a polymorphic loop — all in the exact form the Pseudocode Guide specifies.

What this page covers
  • OOP written in Cambridge pseudocode.
  • The Python versions of the same ideas are on Parts 1, 2 and 4.
  • All pseudocode here follows the 9618 Pseudocode Guide for Teachers (section 10).
KeywordMeaning
CLASS ... ENDCLASSThe block that defines a class in pseudocode.
PRIVATE / PUBLICAccess modifiers. Members are assumed public unless marked PRIVATE.
PROCEDURE / FUNCTIONA method that does something (procedure) or returns a value (function, with RETURNS).
NEWThe constructor: a procedure named NEW that runs when the object is created.
INHERITSMarks a subclass: CLASS Car INHERITS Vehicle.
SUPERCalls the parent class — e.g. SUPER.NEW(...) to reuse the parent constructor.

25.2 Writing a Class with Methods

Why are we doing this?
  • Mark scheme: Mark schemes are written in pseudocode, so even if you code in Python you must read pseudocode classes fluently — and Paper 3 may ask you to write or complete one.
  • The keywords are fixed by the Pseudocode Guide; using the right ones (and pairing every opener with its END…) is where the marks are.
Exam tip: Examiner focus: Section 10 of the 9618 Pseudocode Guide defines the OOP form exactly: methods are PUBLIC PROCEDURE/FUNCTION, members can be PRIVATE, and the access level is only shown when it matters to the question.

A class lists its attributes, then its methods. A method that does something is a PROCEDURE; one that returns a value is a FUNCTION with RETURNS. Use & to join strings.

CLASS Book
    PRIVATE Title  : STRING
    PRIVATE Author : STRING

    PUBLIC PROCEDURE SetDetails(NewTitle : STRING, NewAuthor : STRING)
        Title  <- NewTitle
        Author <- NewAuthor
    ENDPROCEDURE

    PUBLIC FUNCTION GetDetails() RETURNS STRING
        RETURN "Title: " & Title & ", Author: " & Author
    ENDFUNCTION
ENDCLASS

MyBook <- NEW Book()
MyBook.SetDetails("1984", "George Orwell")
OUTPUT MyBook.GetDetails()
Task — Worked Example — Movie class with SetDetails and GetDetails [5 marks]
Write pseudocode. Write a class Movie with private Name and Director, a procedure SetDetails, and a function GetDetails() that returns them. [5]
Hint:
  • CLASS Movie ... ENDCLASS; two PRIVATE attributes.
  • PUBLIC PROCEDURE SetDetails assigns both.
  • PUBLIC FUNCTION GetDetails() RETURNS STRING — return the combined string with &.
Your Turn — Your Turn — Player class with SetScore and GetScore [5 marks]
Write pseudocode. Write a class Player with a private Score (INTEGER), a procedure SetScore, and a function GetScore() that returns it. [5]
Hint:
  • INTEGER attribute; FUNCTION ... RETURNS INTEGER.
Key rule
  • Every block keyword needs its partner: CLASSENDCLASS, PROCEDUREENDPROCEDURE, FUNCTIONENDFUNCTION.
  • A method that returns a value is a FUNCTION with RETURNS <type>; otherwise it is a PROCEDURE.
Exam tip:
  • Use & (not +) to join strings in pseudocode, and assign with (not =).
  • Examiners deduct for Python-isms creeping into a pseudocode answer.

25.3 The NEW Constructor

Why are we doing this?
  • A constructor sets an object's attributes the moment it is created.
  • In pseudocode the constructor is always a procedure named NEW — recognising and writing it is essential for reading mark schemes and for Paper 3 class questions.

Replace SetDetails with NEW so the values are passed when the object is built.

CLASS Book
    PRIVATE Title  : STRING
    PRIVATE Author : STRING

    PUBLIC PROCEDURE NEW(NewTitle : STRING, NewAuthor : STRING)
        Title  <- NewTitle
        Author <- NewAuthor
    ENDPROCEDURE

    PUBLIC FUNCTION GetDetails() RETURNS STRING
        RETURN Title & " by " & Author
    ENDFUNCTION
ENDCLASS

MyBook <- NEW Book("To Kill a Mockingbird", "Harper Lee")
OUTPUT MyBook.GetDetails()
Task — Worked Example 20.1.13B — Movie NEW constructor
Give the Movie class a NEW constructor that initialises Name and Director.
Hint:
  • The constructor is just a procedure named NEW.
Your Turn — Your Turn 20.1.13B — Student NEW constructor
Give a Student class a NEW constructor that initialises Name (STRING) and Grade (INTEGER).
Hint:
  • Two parameters, two assignments.
Key rule
  • In pseudocode the constructor is a PUBLIC PROCEDURE NEW(…).
  • Create an object with Obj ← NEW ClassName(arguments).
Exam tip:
  • The constructor must be named NEW exactly — not Constructor or Init.
  • Object creation then uses the NEW keyword again: Player1 ← NEW Player(…).

25.4 INHERITS and SUPER

Why are we doing this?
  • Inheritance in pseudocode uses one keyword on the class line — INHERITS — and reuses the parent constructor through SUPER.
  • Both come straight from the Pseudocode Guide, and reading them correctly is needed to follow inherited mark schemes.
Exam tip: Examiner focus: The Pseudocode Guide shows inheritance with CLASS Cat INHERITS Pet and the parent constructor called as SUPER.NEW(GivenName) — the exact form expected in answers.
CLASS Vehicle
    PRIVATE Brand : STRING
    PUBLIC PROCEDURE NEW(GivenBrand : STRING)
        Brand <- GivenBrand
    ENDPROCEDURE
    PUBLIC FUNCTION GetBrand() RETURNS STRING
        RETURN Brand
    ENDFUNCTION
ENDCLASS

CLASS Car INHERITS Vehicle
    PRIVATE Model : STRING
    PUBLIC PROCEDURE NEW(GivenBrand : STRING, GivenModel : STRING)
        SUPER.NEW(GivenBrand)         // reuse parent constructor
        Model <- GivenModel
    ENDPROCEDURE
    PUBLIC FUNCTION GetDetails() RETURNS STRING
        RETURN GetBrand() & " " & Model
    ENDFUNCTION
ENDCLASS

MyCar <- NEW Car("Toyota", "Corolla")
OUTPUT MyCar.GetDetails()
Task — Worked Example — Bike INHERITS Vehicle [4 marks]
Write pseudocode. Write a class Bike that INHERITS Vehicle, adds a private BikeType, and uses SUPER to initialise Brand. [4]
Hint:
  • CLASS Bike INHERITS Vehicle; private extra attribute; SUPER.NEW call; store the extra attribute.
Your Turn — Your Turn — Dog INHERITS Pet [4 marks]
Write pseudocode. Write a class Dog that INHERITS Pet (which has NEW(GivenName)), adds a private Breed, and uses SUPER to set the name. [4]
Hint:
  • Same shape as Bike.
Key rule
  • Declare a subclass with CLASS Child INHERITS Parent.
  • Call the parent constructor first with SUPER.NEW(…), then set the child's own attributes.
Exam tip:
  • INHERITS goes on the CLASS line; SUPER.NEW(…) goes as the first line of the child constructor.
  • Putting the SUPER call last, or omitting it, loses the parent-initialisation mark.

25.5 Overriding and Polymorphism

Why are we doing this?
  • Polymorphism lets one loop drive a mixed array of objects, each running its own version of a method.
  • In pseudocode you override by redefining a method with the same name in the subclass, then iterate the array with FOR EACH.
CLASS Animal
    PUBLIC PROCEDURE Speak()
        OUTPUT "This is an animal sound"
    ENDPROCEDURE
ENDCLASS

CLASS Dog INHERITS Animal
    PUBLIC PROCEDURE Speak()          // override
        OUTPUT "Woof Woof"
    ENDPROCEDURE
ENDCLASS

CLASS Cat INHERITS Animal
    PUBLIC PROCEDURE Speak()          // override
        OUTPUT "Meow"
    ENDPROCEDURE
ENDCLASS

DECLARE Animals : ARRAY OF Animal
Animals <- [NEW Dog(), NEW Cat(), NEW Dog()]

FOR EACH A IN Animals
    A.Speak()
NEXT

// Output:
// Woof Woof
// Meow
// Woof Woof
Your Turn — Your Turn — Cow INHERITS Animal [2 marks]
Write pseudocode. Add a class Cow that INHERITS Animal and overrides Speak() to output "Moo". [2]
Hint:
  • Same pattern as Dog and Cat.
Key rule
  • To override, redefine a method with the same name in the subclass.
  • A FOR EACH … NEXT loop over an array of the parent type then calls each object's own version — that is polymorphism.
Exam tip:
  • Keep pseudocode strict: OUTPUT (not print), for assignment, UPPERCASE keywords, and matching END… for every block.
  • Tidy, correct keywords read as confident answers.

25.5B Full Exam-Style Question

Paper 4 · OOP pseudocode · ~14 marks
  • A college stores course details.
  • Each course has a name and a tutor.
  • An online course is a type of course that also has a platform (e.g. “Zoom”).

(a) Write pseudocode to declare a class Course with private Name (STRING) and Tutor (STRING), a NEW constructor, and a GetDetails() function that returns the name and tutor joined into a string. [5]

(b) Write pseudocode to declare a class OnlineCourse that INHERITS Course, adds a private Platform (STRING), uses SUPER to initialise the parent attributes, and overrides GetDetails() to also include the platform. [5]

(c) Write pseudocode to declare an array of 3 Course objects (mix of Course and OnlineCourse), then use a FOR EACH loop to OUTPUT each GetDetails(). [4]

Lab Task — Show full solution & mark scheme
Reveal the model solution and mark scheme for parts (a)–(c).
Hint:
  • (a) CLASS Course; two PRIVATE attributes; PUBLIC PROCEDURE NEW with two params; PUBLIC FUNCTION GetDetails() RETURNS STRING with & joining.
  • (b) CLASS OnlineCourse INHERITS Course; PRIVATE Platform; SUPER.NEW first; override GetDetails to add Platform.
  • (c) DECLARE array; assign NEW Course(...) and NEW OnlineCourse(...); FOR EACH ... NEXT with OUTPUT GetDetails().

Key Points Summary

In Paper 3 and mark schemes the language is Cambridge pseudocode. The OOP ideas are identical to Python — only the keywords change.
A class is CLASS ... ENDCLASS. Every block keyword needs its partner: CLASS/ENDCLASS, PROCEDURE/ENDPROCEDURE, FUNCTION/ENDFUNCTION.
Attributes are declared PRIVATE (or PUBLIC) with a type: PRIVATE Title : STRING. Members are assumed public unless marked PRIVATE.
A method that does something is a PROCEDURE; one that returns a value is a FUNCTION with RETURNS <type>.
The constructor is always a PUBLIC PROCEDURE NEW(...). It runs when the object is created. The name must be NEW exactly — not Constructor or Init.
Create an object with Obj ← NEW ClassName(arguments). The NEW keyword is used both in the constructor name and in object creation.
Assign with ← (not =). Join strings with & (not +). These Python-isms lose marks in a pseudocode answer.
Use OUTPUT (not print) and keep keywords UPPERCASE: CLASS, PRIVATE, PUBLIC, PROCEDURE, FUNCTION, RETURNS, NEW, INHERITS, SUPER, OUTPUT.
Declare a subclass with CLASS Child INHERITS Parent. The child gets all the parent's attributes and methods.
Call the parent constructor with SUPER.NEW(...) as the FIRST line of the child constructor, then set the child's own attributes.
INHERITS goes on the CLASS line; SUPER.NEW(...) goes as the first line of the child constructor. Putting SUPER last or omitting it loses the parent-init mark.
To override a method, redefine it with the same name in the subclass. The subclass's version runs instead of the parent's. No special keyword is needed.
Polymorphism: a FOR EACH ... NEXT loop over an array of the parent type calls each object's own overridden version of the method.
Mark schemes are written in pseudocode, so even if you code in Python you must read pseudocode classes fluently — and Paper 3 may ask you to write one.
Tidy, correct keywords read as confident answers: pair every opener with its END..., use the right symbols, and keep keywords UPPERCASE.

25.6 Practice Tasks

Fifteen exam-style tasks. Click Hint for bullet-point guidance, then Help to reveal a worked pseudocode solution.

1Practice Task — Write a class with a procedure [5 marks]
Write pseudocode for a class Song with PRIVATE Title and Artist (STRING), a PUBLIC PROCEDURE SetDetails, and a PUBLIC FUNCTION GetTitle() RETURNS STRING.
2Practice Task — Write a NEW constructor [4 marks]
Write pseudocode for a class Product with PRIVATE Name (STRING) and Price (REAL), and a PUBLIC PROCEDURE NEW that initialises both.
3Practice Task — Function that returns a value [4 marks]
Add to the Product class a PUBLIC FUNCTION GetPrice() RETURNS REAL that returns the Price attribute.
4Practice Task — Create an object and call methods [3 marks]
Write pseudocode to create a Product object named Item with "Pen" and 1.50, then OUTPUT its price using GetPrice().
5Practice Task — INHERITS and SUPER [5 marks]
Write pseudocode for a class Vehicle with PRIVATE Brand and NEW(GivenBrand). Then write a class Truck INHERITS Vehicle that adds PRIVATE LoadCapacity (REAL) and uses SUPER.NEW.
6Practice Task — Override a method [4 marks]
A class Animal has PUBLIC PROCEDURE Speak() OUTPUT "Generic sound". Write a class Cat INHERITS Animal that overrides Speak() to OUTPUT "Meow".
7Practice Task — Polymorphism loop [4 marks]
Given Animals = [NEW Dog(), NEW Cat(), NEW Dog()], write a FOR EACH loop that calls Speak() on each. Dog outputs "Woof Woof", Cat outputs "Meow". What is the output?
8Practice Task — Spot the Python-ism [3 marks]
A student wrote: `Title = NewTitle` and `RETURN "Title: " + Title` in pseudocode. What is wrong, and what are the fixes?
9Practice Task — Missing END partner [2 marks]
A student wrote a class with CLASS and PROCEDURE but no ENDCLASS or ENDPROCEDURE. What is wrong?
10Practice Task — Full class with constructor and getter [6 marks]
Write pseudocode for a class Student with PRIVATE Name (STRING) and Mark (INTEGER), a NEW constructor, and a PUBLIC FUNCTION GetMark() RETURNS INTEGER.
11Practice Task — Inheritance with override [7 marks]
Write pseudocode for a class Person with PRIVATE Name and NEW(GivenName). Then write a class Student INHERITS Person that adds PRIVATE StudentID (STRING), uses SUPER.NEW, and adds a function GetID() RETURNS STRING.
12Practice Task — Array of objects + loop [5 marks]
Write pseudocode to DECLARE an array of 3 Student objects, create three students, then use FOR EACH to OUTPUT each student's GetID().
13Practice Task — Constructor name [2 marks]
A student named the constructor `Init` instead of `NEW`. What is wrong, and why does it matter?
14Practice Task — SUPER placement [3 marks]
A student wrote SUPER.NEW(GivenBrand) as the LAST line of the child constructor. What is wrong, and what is the fix?
15Practice Task — Full exam-style: Course/OnlineCourse [14 marks]
(a) Write a class Course with PRIVATE Name and Tutor, NEW, and GetDetails() RETURNS STRING [5]. (b) Write OnlineCourse INHERITS Course adding Platform, using SUPER, overriding GetDetails [5]. (c) Declare an array of 3 mixed Course objects and FOR EACH OUTPUT GetDetails [4].

Question Bank

Answer all questions, then press Submit Quiz to see your score.

0/12 answered

Question 1Multiple Choice

In Cambridge pseudocode, a class block is:

Question 2Multiple Choice

A method that returns a value is a:

Question 3True / False

In pseudocode, the constructor is a procedure named NEW.

Question 4Multiple Choice

How do you create an object in pseudocode?

Question 5Multiple Choice

In pseudocode, how do you declare a subclass?

Question 6Multiple Choice

How do you call the parent constructor in pseudocode?

Question 7True / False

In pseudocode, use & to join strings (not +).

Question 8Multiple Choice

In pseudocode, assignment uses which symbol?

Question 9Multiple Choice

How do you override a method in pseudocode?

Question 10Multiple Choice

Which loop is used for polymorphism over a mixed array?

Question 11Multiple Choice

In pseudocode, which keyword reuses the parent constructor?

Question 12True / False

In pseudocode, OUTPUT is used instead of print.

Answer all 12 questions to enable submission.