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.

Member variableTypeDescription
lengthintegerDimension of length.
widthintegerDimension of width.
ConstructorDescription
Rectangle(integer: _length,integer: _width)Initialize member variable length with _length and member variable width with _width.
MethodReturn valueDescription
enlarge(Rectangle:shape)NoneTo increase the size, add shape.length to length and shape.width to width.
output()NoneOutput in format “(length, width)”.

Figure 1 Class Rectangle

Member variableTypeDescription
heightintegerDimension of height.
ConstructorDescription
Cuboid(integer: _length,integer: _width,integer: _height)Constructor of the super class is called with _length and _width as arguments in that order, and member variable height is initialized with the argument _height.
MethodReturn valueDescription
enlarge(Cuboid:shape)NoneTo increase the size, add shape.length to length, shape.width to width and shape.height to height.
output()NoneOutput in format “(length, width, height)”.

Figure 2 Class Cuboid

When the program is executed, it is expected to produce the output “blank”.

[Program]
Rectangle: f1 ← Rectangle(5, 2)
Cuboid: f2 ← Cuboid(9, 4, 7)
f1.enlarge(f2)
f1.output()

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): length 5, width 2
  • •f2 ← Cuboid(9, 4, 7): calls Rectangle(9, 4), then sets height to 7
  • •f1.enlarge(f2): f1 is a Rectangle, so enlarge(Rectangle: shape) runs. A Cuboid is a Rectangle, so f2 is a valid argument, and the method adds only shape.length and shape.width: length becomes 5 + 9 = 14, width becomes 2 + 4 = 6
  • •f1.output(): the Rectangle format, two values, (14, 6)

f2.height is never read, and f1 has no height to change.

Answer (e)

Why not others:

  • •(a) (5, 2) — ignores f1.enlarge(f2), which changes f1
  • •(b) (5, 2, 7) — ignores the enlargement and gives f1 a third value that a Rectangle does not have
  • •(c) (9, 4) — treats enlarge as copying the dimensions of f2 instead of adding them
  • •(d) (9, 4, 7) — prints the initial state of f2, not f1
  • •(f) (14, 6, 7) — adds correctly but then prints as a Cuboid; f1 is a Rectangle, whose output has 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.