Code Lab

Modo entrevista. Temporizador de 6 min, sin pistas y sin autocompletado

Cuboid and cube

FácilClasses6 min

Write a class Cuboid. The constructor new Cuboid(length, width, height) stores the sizes in the fields length, width and height. The getter volume returns the volume, the getter surfaceArea returns the total surface area.

Then write a class Cube that extends Cuboid. Its constructor takes only the edge length.

Ejemplos

new Cuboid(1, 2, 3).volume

Devuelve 6

new Cuboid(1, 2, 3).surfaceArea

Devuelve 22

Six faces, two of each kind.
new Cube(2).volume

Devuelve 8

Fuente

Cargando el editor…
  1. The constructor stores the sizes
  2. Cuboid volume
  3. Cuboid surface area
  4. Cube volume and area
  5. Cube extends Cuboid

Las pruebas ocultas se ejecutan al enviar