Cambridge 9618 · International A Level Computer Science · ~20 min read
Notes
Video
Slides
Quiz
Worksheet
Class Definition in Cambridge 9618 Pseudocode
A class is a template that defines the attributes and methods for a type of object. In Cambridge 9618 pseudocode, classes are defined using CLASS...ENDCLASS.
CLASS Animal PRIVATE name : STRING PRIVATE age : INTEGER
PUBLICPROCEDURE NEW(n : STRING, a : INTEGER)
name ← n // constructor — sets initial attribute values
age ← a ENDPROCEDURE
PUBLICPROCEDURE SetName(n : STRING)
name ← n ENDPROCEDURE
PUBLICFUNCTION GetName() RETURNS STRING RETURN name ENDFUNCTION
PUBLICPROCEDURE Describe()
OUTPUT name & " is " & age & " years old" ENDPROCEDURE ENDCLASS
Class Diagram Representation
Animal
Attributes
- name : STRING
- age : INTEGER
Methods
+ NEW(n : STRING, a : INTEGER)
+ SetName(n : STRING)
+ GetName() : STRING
+ Describe()
Notation: - (minus) = PRIVATE | + (plus) = PUBLIC
Creating and Using Objects
// Declare an object variable DECLARE myAnimal : Animal
// Create an instance using the constructor
myAnimal ← NEW Animal("Lion", 5)
// Call methods using dot notation
myAnimal.Describe() // outputs: Lion is 5 years old
myAnimal.SetName("Tiger")
OUTPUT myAnimal.GetName() // outputs: Tiger
The Four Pillars of OOP
🔒
Encapsulation
Bundling attributes and methods inside a class. Private attributes are hidden — only accessible through public methods (getters/setters). Protects data integrity.
🧬
Inheritance
A subclass inherits all attributes and methods from a superclass using INHERITS keyword. The subclass can add new attributes/methods and override inherited methods.
🎭
Polymorphism
Different objects respond to the same method call in different ways. A subclass can override a superclass method — the overridden version runs for subclass objects.
🗺️
Abstraction
Hiding complex implementation details and exposing only a clean interface. Users of a class interact with it through its public methods without knowing the internal code.
Inheritance
A subclass (also called child class or derived class) inherits all the public and protected attributes and methods of a superclass (parent class). Use the INHERITS keyword in Cambridge 9618 pseudocode.
CLASS Dog INHERITS Animal PRIVATE breed : STRING
PUBLICPROCEDURE NEW(n : STRING, a : INTEGER, b : STRING) CALL SUPER.NEW(n, a) // call parent constructor
breed ← b ENDPROCEDURE
PUBLICPROCEDURE Describe() // override superclass method
OUTPUT GetName() & " is a " & breed ENDPROCEDURE ENDCLASS
Using the Subclass
DECLARE myDog : Dog
myDog ← NEW Dog("Rex", 3, "Labrador")
myDog.Describe() // uses OVERRIDDEN version → "Rex is a Labrador"
OUTPUT myDog.GetName() // inherited from Animal → "Rex"
OUTPUT myDog.GetBreed() // Dog's own method → "Labrador"
Encapsulation — Getters and Setters
Because attributes are PRIVATE, external code cannot access them directly. Getter methods return an attribute value; setter methods update it. This allows validation inside the setter.
// Direct access would fail — name is PRIVATE:
OUTPUT myAnimal.name // ERROR — private attribute
// Correct approach — use getter:
OUTPUT myAnimal.GetName() // OK — public method
// Setter with validation example: PUBLICPROCEDURE SetAge(a : INTEGER) IF a >= 0THEN
age ← a ELSE
OUTPUT "Age cannot be negative" ENDIF ENDPROCEDURE
Polymorphism
When a subclass overrides a superclass method, calling that method on a subclass object uses the overridden version. This lets the same method name behave differently for different object types.
DECLARE a1 : Animal DECLARE d1 : Dog
a1 ← NEW Animal("Cat", 2)
d1 ← NEW Dog("Rex", 3, "Labrador")
a1.Describe() // Animal.Describe() → "Cat is 2 years old"
d1.Describe() // Dog.Describe() (overridden) → "Rex is a Labrador" // Same method name, different behaviour — this is POLYMORPHISM
Full Example — Bank Account System
CLASS Account PRIVATE owner : STRING PRIVATE balance : REAL
PUBLICPROCEDURE NEW(o : STRING, b : REAL)
owner ← o
balance ← b ENDPROCEDURE
Cambridge 9618 pseudocode syntax rules for OOP: CLASS/ENDCLASS for class definition; PRIVATE/PUBLIC access modifiers; NEW as the constructor name; INHERITS for inheritance; CALL SUPER.NEW() to invoke the parent constructor; dot notation for method calls (obj.Method()); DECLARE obj : ClassName then obj ← NEW ClassName(args) to create objects.
Getter/Setter naming convention: Cambridge mark schemes expect getters named GetX() returning the attribute, and setters named SetX(value) updating the attribute. Always make attributes PRIVATE and provide public getter/setter methods.
Forgetting to call SUPER.NEW() in a subclass constructor — parent attributes won't be initialised
Confusing 'class' and 'object' — class is the template (no data), object is the instance (has data)
Not using dot notation to call methods — write myDog.Describe(), not Describe(myDog)
Writing constructor as FUNCTION instead of PROCEDURE — NEW is a PROCEDURE (returns nothing)
Forgetting ENDCLASS — every CLASS definition needs ENDCLASS at the end
✅ Notes completed!
▶
Video coming soon
Click slide or press arrow keys to navigate
Worksheet — 2.5.2 Object-Oriented Programming
8 questions · Cambridge 9618 standard
Q1Define a class called Rectangle with PRIVATE attributes width and height (both REAL). Include a PUBLIC constructor NEW that takes two REAL parameters, and a PUBLIC FUNCTION Area() that returns the area.[6]
✅ Mark scheme
CLASS Rectangle [1]; PRIVATE width : REAL; PRIVATE height : REAL [1]; PUBLIC PROCEDURE NEW(w : REAL, h : REAL) [1]; width ← w; height ← h; ENDPROCEDURE [1]; PUBLIC FUNCTION Area() RETURNS REAL [1]; RETURN width * height; ENDFUNCTION [1]; ENDCLASS.
Q2Write pseudocode to: (a) declare an object myRect of class Rectangle, (b) create a Rectangle with width=5.0 and height=3.0, (c) output the area.[3]
Q3Explain what 'encapsulation' means in OOP and state why attributes are usually declared as PRIVATE.[3]
✅ Mark scheme
Encapsulation bundles attributes and methods together inside a class and hides internal implementation details from external code [1]; attributes are PRIVATE so external code cannot access or modify them directly [1]; this protects data integrity — only class methods can change attribute values, allowing validation to be included in setter methods [1].
Q4Define a class Square that INHERITS from Rectangle. Square has only one dimension (side). Its constructor should take one REAL parameter and call the parent constructor appropriately.[5]
✅ Mark scheme
CLASS Square INHERITS Rectangle [1]; PUBLIC PROCEDURE NEW(s : REAL) [1]; CALL SUPER.NEW(s, s) [1]; ENDPROCEDURE [1]; ENDCLASS [1]. (Award marks for correct INHERITS, constructor with one parameter, calling SUPER.NEW with both dimensions as s, and correct ENDCLASS.)
Q5Explain polymorphism using an example from OOP. How does method overriding relate to polymorphism?[4]
✅ Mark scheme
Polymorphism means different objects can respond to the same method call in different ways [1]; a subclass can override a superclass method to provide a different implementation [1]; example: Animal.Describe() outputs "name is age years old"; Dog.Describe() (overridden) outputs "name is a breed" — both objects respond to Describe() but with different behaviour [1]; when Describe() is called on a Dog object, the Dog's overriding version runs, not the Animal version [1].
Q6State one advantage of using inheritance in OOP, with an example to support your answer.[2]
✅ Mark scheme
Any one with example: Code reuse — the subclass inherits all public methods of the superclass without rewriting them; e.g. Dog inherits GetName() and Describe() from Animal [2]; Extensibility — new subclasses can be added that extend the superclass without modifying existing code; e.g. Cat and Dog can both inherit from Animal [2].
Q7A software team is developing a new school management system. Explain why the waterfall model would be unsuitable for this project, and describe how the iterative (agile) model would be more appropriate. Include reference to requirements gathering, prototyping, and stakeholder feedback.[5]
✅ Mark scheme
Waterfall: requirements must be fixed at start, difficult to change later — 1 mark; unsuitable because school requirements often change as stakeholders see early versions — 1 mark; Iterative: develops in sprints/cycles, delivers working prototypes early — 1 mark; stakeholders review each prototype and feed back changes before next cycle — 1 mark; requirements can be refined throughout, reducing risk of final product mismatch — 1 mark.
Q8Describe the purpose of each of the following activities in the software development lifecycle: (i) requirements analysis, (ii) design, (iii) maintenance. For each, state one specific output or deliverable produced.[6]
✅ Mark scheme
Requirements analysis: defines what the system must do based on stakeholder needs — 1 mark; deliverable: requirements specification document — 1 mark; Design: determines how the system will be built — architecture, algorithms, data structures — 1 mark; deliverable: system design document / UML diagrams / structure charts — 1 mark; Maintenance: fixes bugs, adds features, adapts to new environments after deployment — 1 mark; deliverable: updated software versions / patch notes / change log — 1 mark.
Topic Quiz
Question 1 of 10
You scored
out of 10
Card 1 of 8
Click to reveal definition
🎉
All cards reviewed!
Term
Definition
🎯
Mini Test — 2.5.2 OOP
10 questions · 10 marks · 10 minutes
⏱ 10:00
Section A — Multiple Choice [5 marks]
Q1In Cambridge 9618, what keyword is used to define a class that inherits from another?
Q2What access modifier should class attributes normally be declared with?
Q3How do you create an instance of class Animal with name "Cat" and age 2 in Cambridge 9618 pseudocode?
Q4Which OOP concept allows the same method name to produce different behaviour in different subclasses?
Q5In a subclass constructor, how is the parent class constructor called in Cambridge 9618?
Section B — Short Answer [5 marks]
Q6Explain why a getter method is needed when an attribute is PRIVATE. Give an example in pseudocode.
Mark schemePRIVATE attributes cannot be accessed directly from outside the class [1]; a getter is a PUBLIC method that returns the value of the private attribute [1]; example: PUBLIC FUNCTION GetName() RETURNS STRING; RETURN name; ENDFUNCTION — called as obj.GetName() [1].
Q7What is the purpose of the constructor (NEW) method in a class definition?
Mark schemeThe constructor (NEW) is automatically called when an object is created [1]; it initialises the object's attributes to their starting values using the parameters passed in [1]; in Cambridge 9618 it is declared as PUBLIC PROCEDURE NEW(params) and called using ← NEW ClassName(args) [1].
Q8State two benefits of inheritance in OOP.
Mark schemeAny two: Code reuse — inherited methods do not need to be rewritten in the subclass [1]; Extensibility — new subclasses can extend the superclass behaviour without modifying existing code [1]; Consistency — all subclasses share the superclass interface, making the system more predictable [1].
Q9Write pseudocode for a class Vehicle with PRIVATE attribute speed (INTEGER), a PUBLIC setter SetSpeed that rejects negative values, and a PUBLIC getter GetSpeed.
Mark schemeCLASS Vehicle [1]; PRIVATE speed : INTEGER [1]; PUBLIC PROCEDURE SetSpeed(s : INTEGER); IF s >= 0 THEN speed ← s ELSE OUTPUT "Invalid" ENDIF; ENDPROCEDURE [1]; PUBLIC FUNCTION GetSpeed() RETURNS INTEGER; RETURN speed; ENDFUNCTION [1]; ENDCLASS [1].
Q10Describe what happens when Dog overrides the method Describe() from Animal, and both Dog and Animal objects call Describe().
Mark schemeWhen an Animal object calls Describe(), the Animal class's version runs [1]; when a Dog object calls Describe(), the Dog class's overriding version runs instead of Animal's version [1]; this is polymorphism — the same method name produces different behaviour depending on the type of object [1].