Unit 7: B3 Object-oriented programming
Topic 7.2: OOP: multiple classes Questions
Practice 20 exam-style questions for IB Computer Science Topic 7.2. Review the question stems below, then unlock the full Question Bank to access markschemes, model answers, and AI grading.
1Construct4 marks
2026
A Python class Bike has the constructor def __init__(self, model, gears). Construct the code for a subclass EBike that adds an attribute battery_level starting at 100, with a constructor and an accessor and mutator for battery_level, without repeating the attributes and methods of Bike.
Markscheme and model answer locked
Unlock Question2Construct4 marks
2026
A Java class Bike has the constructor public Bike(String model, int gears). Construct the code for a subclass EBike that adds an int attribute batteryLevel starting at 100, with a constructor and an accessor and mutator for batteryLevel, without repeating the attributes and methods of Bike.
Markscheme and model answer locked
Unlock Question3Describe2 marks
2026
In a Java class Account, the method applyInterest() is declared protected. Describe the use of the modifier protected for this method.
Markscheme and model answer locked
Unlock Question4Describe2 marks
2026
In a drawing program, Circle and Rectangle extend Shape, and Shape declares calculateArea() as protected. Describe which code can call calculateArea() and which cannot.
Markscheme and model answer locked
Unlock Question5Outline2 marks
2027
In a sports app, a Team object holds a list of Player objects, and players exist even when they are not in a team. Outline the relationship between Team and Player.
Markscheme and model answer locked
Unlock Question6Construct3 marks
2027
A cinema program has this Python class:
class Ticket:
def __init__(self, base):
self.base = base
def price(self):
return self.base
Construct a class ChildTicket that inherits from Ticket and overrides price() so that a child pays half the base price.
Markscheme and model answer locked
Unlock Question7Explain3 marks
2027
A transport app has classes Car, Bus and Bike, which all store a registration ID and a top speed and all have a describe() method. Explain how inheritance promotes code reusability here.
Markscheme and model answer locked
Unlock Question8Construct4 marks
2027
A payroll program has this Python class:
class Employee:
def __init__(self, name, salary):
self.name = name
self.salary = salary
def describe(self):
return self.name + " earns " + str(self.salary)
Construct a class Manager that inherits from Employee and also stores the size of the manager's team.
Markscheme and model answer locked
Unlock Question9Construct4 marks
2027
A payroll program has this Java class:
class Employee {
protected String name;
protected double salary;
Employee(String name, double salary) {
this.name = name;
this.salary = salary;
}
String describe() {
return name + " earns " + salary;
}
}
Construct a class Manager that inherits from Employee and also stores the size of the manager's team.
Markscheme and model answer locked
Unlock Question10Construct3 marks
2027
A cinema program has this Java class:
class Ticket {
protected double base;
Ticket(double base) {
this.base = base;
}
double price() {
return base;
}
}
Construct a class ChildTicket that inherits from Ticket and overrides price() so that a child pays half the base price.
Markscheme and model answer locked
Unlock Question11Explain3 marks
2027
A cinema stores AdultTicket, ChildTicket and StudentTicket objects, each overriding price(), in one list. Explain how polymorphism lets the program total the prices with a single loop.
Markscheme and model answer locked
Unlock Question12Construct4 marks
2027
A smart-home program has this abstract Python class:
from abc import ABC, abstractmethod
class Sensor(ABC):
def __init__(self, location):
self.location = location
@abstractmethod
def read(self):
pass
Construct a class TemperatureSensor that inherits from Sensor, stores a temperature in degrees, and implements read() to return it.
Markscheme and model answer locked
Unlock Question13Construct4 marks
2027
A smart-home program has this abstract Java class:
abstract class Sensor {
protected String location;
Sensor(String location) {
this.location = location;
}
abstract double read();
}
Construct a class TemperatureSensor that inherits from Sensor, stores a temperature in degrees, and implements read() to return it.
Markscheme and model answer locked
Unlock Question14Explain3 marks
2027
A game has an abstract class Enemy with an abstract method attack(). Explain why the program cannot create an Enemy object, and what the abstract class is used for instead.
Markscheme and model answer locked
Unlock Question15Describe3 marks
2027
A weather station object must update a phone display, a web page and an alarm whenever the temperature changes. Describe how the observer pattern could be used.
Markscheme and model answer locked
Unlock Question16Explain3 marks
2027
In a drawing app the user picks "circle", "square" or "triangle" from a menu. Explain how the factory pattern helps create the right shape object.
Markscheme and model answer locked
Unlock Question17Outline2 marks
2026
A ferry operator's Sailing class holds an array of Booking objects, and a Booking's fare is set by the Sailing when the booking is made — a Booking cannot exist without its Sailing. Outline the relationship between the Booking and Sailing classes.
Markscheme and model answer locked
Unlock Question18Describe2 marks
2026
In a garage system, the Vehicle class declares the method logService() as protected. Describe the use of protected for this method.
Markscheme and model answer locked
Unlock Question19State1 mark
2026
A Geometry class has area(double r) and area(double w, double h). State the OOP concept that allows two methods in the same class to share a name.
Markscheme and model answer locked
Unlock Question20State1 mark
2026
A Catalogue class has find(int id) and find(String title). State the OOP concept shown.
Markscheme and model answer locked
Unlock QuestionReady to practice Topic 7.2?
Get instant AI feedback on your answers, view detailed markschemes, and track your progress across all IB Computer Science topics.
Start Practising Now