OOP & Inheritance

OOP & Inheritance

1 question · Fundamental Engineering

Practice

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