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.
- 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).
| Keyword | Meaning |
|---|---|
| CLASS ... ENDCLASS | The block that defines a class in pseudocode. |
| PRIVATE / PUBLIC | Access modifiers. Members are assumed public unless marked PRIVATE. |
| PROCEDURE / FUNCTION | A method that does something (procedure) or returns a value (function, with RETURNS). |
| NEW | The constructor: a procedure named NEW that runs when the object is created. |
| INHERITS | Marks a subclass: CLASS Car INHERITS Vehicle. |
| SUPER | Calls the parent class — e.g. SUPER.NEW(...) to reuse the parent constructor. |
25.2 Writing a Class with Methods
- 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.
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()- CLASS Movie ... ENDCLASS; two PRIVATE attributes.
- PUBLIC PROCEDURE SetDetails assigns both.
- PUBLIC FUNCTION GetDetails() RETURNS STRING — return the combined string with &.
- INTEGER attribute; FUNCTION ... RETURNS INTEGER.
- Every block keyword needs its partner:
CLASS…ENDCLASS,PROCEDURE…ENDPROCEDURE,FUNCTION…ENDFUNCTION. - A method that returns a value is a
FUNCTIONwithRETURNS <type>; otherwise it is aPROCEDURE.
- Use
&(not+) to join strings in pseudocode, and assign with←(not=). - Examiners deduct for Python-isms creeping into a pseudocode answer.
25.2 Writing a Class with Methods
25.3 The NEW Constructor
- 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()- The constructor is just a procedure named NEW.
- Two parameters, two assignments.
- In pseudocode the constructor is a
PUBLIC PROCEDURE NEW(…). - Create an object with
Obj ← NEW ClassName(arguments).
- The constructor must be named
NEWexactly — notConstructororInit. - Object creation then uses the
NEWkeyword again:Player1 ← NEW Player(…).
25.3 The NEW Constructor
25.4 INHERITS and SUPER
- Inheritance in pseudocode uses one keyword on the class line —
INHERITS— and reuses the parent constructor throughSUPER. - Both come straight from the Pseudocode Guide, and reading them correctly is needed to follow inherited mark schemes.
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()- CLASS Bike INHERITS Vehicle; private extra attribute; SUPER.NEW call; store the extra attribute.
- Same shape as Bike.
- Declare a subclass with
CLASS Child INHERITS Parent. - Call the parent constructor first with
SUPER.NEW(…), then set the child's own attributes.
INHERITSgoes on theCLASSline;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.4 INHERITS and SUPER
25.5 Overriding and Polymorphism
- 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- Same pattern as Dog and Cat.
- To override, redefine a method with the same name in the subclass.
- A
FOR EACH … NEXTloop over an array of the parent type then calls each object's own version — that is polymorphism.
- Keep pseudocode strict:
OUTPUT(not print),←for assignment, UPPERCASE keywords, and matchingEND…for every block. - Tidy, correct keywords read as confident answers.
25.5 Overriding and Polymorphism
25.5B Full Exam-Style Question
- 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]
- (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
25.6 Practice Tasks
Fifteen exam-style tasks. Click Hint for bullet-point guidance, then Help to reveal a worked pseudocode solution.
Question Bank
Answer all questions, then press Submit Quiz to see your score.
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.