32 exam-style questions on Fundamentals of OOP for multiple classes — topic B3.2 of Object-oriented programming in the IB Computer Science syllabus — with answers and explanations. Samples below; the full set is free with an account.
A program models Vehicle, Van, Wheel and Driver. Which pair is best modelled by inheritance?
Answer: Van and Vehicle, because a van is a kind of vehicle
Inheritance models an is-a relationship, so only the subclass/superclass pair qualifies. Owning or using another object is a has-a relationship and is modelled by aggregation or composition.
The superclass Shape defines area() and the subclasses Square and Circle each override it. A loop takes every object from a collection of Shape objects and executes output OBJ.area(). What happens?
Answer: Each object runs the version of area() defined in its own subclass.
This is polymorphism: the version that runs is chosen from the actual object, not from the type of the variable holding it. It is what lets one loop serve every shape without a decision for each kind.
A House object creates its Room objects when it is built, and those rooms are discarded when the house object is destroyed. Which relationship does this describe?
Answer: Composition, because the rooms cannot exist without the house
Composition is the strong form of has-a: the lifetime of the part is tied to the whole. If the rooms could be handed to another house and survive, it would be aggregation.
Which statement about an abstract class is correct?
Answer: It cannot be instantiated and exists to be inherited from.
An abstract class collects what its subclasses have in common and may leave methods for them to supply, so it cannot be instantiated directly and is used only as a superclass. It may still hold attributes, a constructor and finished methods.
A subclass has to set up the attributes it inherits as well as the ones it adds itself. What does its constructor normally do first?
Answer: Call the constructor of its superclass
The superclass constructor already contains the code that initialises the inherited attributes, so calling it avoids duplicating that code and guarantees the object is set up the same way whichever subclass is being built. Holding a separate superclass object beside the subclass object would be aggregation, not inheritance, and the subclass would then have two identities rather than one.
A library models Member and BannedMember. The same person is banned and reinstated many times while the program is running. Identify the fact in this scenario that rules out making BannedMember a subclass of Member.
Answer: An object cannot change the class it belongs to once it has been created.
Inheritance fixes the class of an object for its whole life, so a status that switches back and forth has to be held as data inside one Member object, for example through a Ban object it refers to, rather than as a class the person is.
That was 6 of 32 Fundamentals of OOP for multiple classes questions.
Practise all 32 freeDistinguishAO2 · 2–4 marks
Make the difference clear for BOTH terms — a definition of one of them is only half an answer.
OutlineAO1 · 1–2 marks
A brief account or summary: the main points in two or three sentences, no evaluation.
StateAO1 · 1–2 marks
One word or one short sentence. No explanation, no working: the mark is for the fact itself.
32 Fundamentals of OOP for multiple classes questions — free with an account. Spaced repetition, streaks and full exam simulations included.
Practise them freeThis platform is independently developed and is not endorsed by, affiliated with, or sponsored by the International Baccalaureate Organization. “International Baccalaureate” and “IB” are registered trademarks of the IBO.