ITPEC FE Subject B October 2025 Question 6
From the answer group below, select the correct answer to be inserted into blank in the description.
Class Rectangle represents a two-dimensional figure, and class Cuboid represents a three-dimensional figure. The class Cuboid is a subclass of the class Rectangle. Figures 1 and 2 explain the classes Rectangle and Cuboid, respectively.
Figure 1 Class Rectangle
Figure 2 Class Cuboid
When the program is executed, it is expected to produce the output “blank”.
Answer group
Explanation
(14, 6) — f1 is a Rectangle, so its enlarge and output are the Rectangle versions, which know only length and width.
- •
f1 ← Rectangle(:5, 2) length5,width2 - •
f2 ← Cuboid(: calls9, 4, 7) Rectangle(, then sets9, 4) heightto 7 - •
f1.:enlarge( f2) f1is aRectangle, soenlarge(runs. ARectangle: shape) Cuboidis aRectangle, sof2is a valid argument, and the method adds onlyshape.andlength shape.:width lengthbecomes 5 + 9 = 14,widthbecomes 2 + 4 = 6 - •
f1.: theoutput( ) Rectangleformat, two values, (14, 6)
f2. is never read, and f1 has no height to change.
Answer (e)
Why not others:
- •(a) (5, 2) — ignores
f1., which changesenlarge( f2) f1 - •(b) (5, 2, 7) — ignores the enlargement and gives
f1a third value that aRectangledoes not have - •(c) (9, 4) — treats
enlargeas copying the dimensions off2instead of adding them - •(d) (9, 4, 7) — prints the initial state of
f2, notf1 - •(f) (14, 6, 7) — adds correctly but then prints as a
Cuboid;f1is aRectangle, whoseoutputhas only length and width
Key rule: The object a method is called on decides which class's method runs; a subclass instance passed as a superclass argument is used only through the superclass's members.
OOP & Inheritance · AI-written, may contain errors
This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.