Cambridge A2 Level Computer Science 9618 · 20.1 Programming Paradigms

Q7 · 9618/31/O/N/22 Q11

Worked solution from the Further Programming Paper 3 Advanced Theory booklet, Part 1 of 2.

Q79618/31/O/N/22original Q11Structured · 8 marks
Question 11 from 9618/31/O/N/22

Worked solution

(a)

Write one definition for each term:

Instance: a specific object made from a class (an instantiation of the class) [1]

Inheritance: defining a new class that gets all the attributes and methods of a parent class [1]

Polymorphism: the same method can behave differently depending on the class used (methods can be redefined in derived classes) [1]

(b)

Name the class, declare the other four PRIVATE attributes, add the constructor parameters, assign them, and close the class.

CLASS Car
    PRIVATE Make : STRING
    PRIVATE Model : STRING
    PRIVATE BodyType : STRING
    PRIVATE Fuel : STRING
    PRIVATE NumberBuilt : INTEGER
    PUBLIC PROCEDURE NEW(CarMake : STRING, CarModel : STRING, CarBodyType : STRING)
        Make ← CarMake
        Model ← CarModel
        BodyType ← CarBodyType
        Fuel ← ""
        NumberBuilt ← 0
    ENDPROCEDURE
    GetFuel()
    GetNumberBuilt()
ENDCLASS

CLASS Car and ENDCLASS [1]

Four PRIVATE declarations (Model, BodyType, Fuel as STRING and NumberBuilt as INTEGER) using the identifiers in the assignments [1]

Constructor header with the parameter CarBodyType [1]

Assignments Make ← CarMake and Model ← CarModel [1]

The constructor parameter for the model matches the identifier in the Model assignment [1]

KEY IDEAA class keeps its attributes PRIVATE and sets them in a constructor; inheritance reuses a parent class and polymorphism lets methods differ by class.
TOTAL 8 marks

Official mark scheme

Mark scheme for 9618/31/O/N/22 question 11
VIDEO
▶ Whole paper

Video solution of the whole paper · by MAK CS. Tap the picture to open it on YouTube.

Solutions follow the official Cambridge mark schemes; marks are shown in grey. Videos are from other YouTube channels. Paper codes read component / series / year: M/J = May/June, O/N = October/November. Past-paper questions © UCLES, reproduced for classroom practice.