Question bank › A-level Computer Science › Fundamentals of programming

Programming paradigms and object-oriented programming

Answer on paper first, then reveal the mark scheme one mark at a time.

1Core3 marks

(a) State what is meant by encapsulation in object-oriented programming. [1]

(b) Explain two differences between a local variable and a global variable. [2]

2Standard6 marks

The Python program below defines two classes.

class Vehicle:
    def __init__(self, reg, wheels):
        self.__reg = reg
        self._wheels = wheels

    def describe(self):
        return self.__reg + " has " + str(self._wheels) + " wheels"

class Lorry(Vehicle):
    def __init__(self, reg, wheels, maxLoad):
        super().__init__(reg, wheels)
        self.__maxLoad = maxLoad

    def describe(self):
        return super().describe() + ", max load " + str(self.__maxLoad) + " tonnes"

l = Lorry("KX70 ABC", 6, 26)
print(l.describe())

(a) Identify the name of the subclass. [1]

(b) Identify a method that has been overridden. [1]

(c) State the exact output when the program is run. [2]

(d) The attribute __reg is private. Explain why a programmer would make an attribute private and how other objects could still be allowed to read its value. [2]

3Stretch6 marks

The class diagram shows part of a drawing application. Shape is an abstract class; its method area is abstract (shown in italics).

(a) State the type of relationship between Drawing and Shape shown by the hollow diamond, and explain what it means for the lifetime of the Shape objects. [2]

(b) Explain why area has been declared as an abstract method in Shape rather than being implemented there. [2]

(c) The attribute shapes is a list of Shape objects. Write the method totalArea for the Drawing class so that it returns the total area of all the shapes in the drawing. Your method must make use of polymorphism. You may use pseudo-code or a programming language you have studied. [2]

Drawing- shapes+ add(s)+ totalArea() Shape + area() Circle- radius+ area() Rectangle- width- height+ area() 0..*

Stuck on this topic?

Book a free 30-minute session on WhatsApp and we'll find exactly which step is costing you the marks. Or build a timed paper on it.

Free 30-minute session