```html Problem Statement: Box & Cube (Inheritance)

NBKRIST Java Hub

← Back to Exam Panel

Problem Statement: Boxes with Inheritance

Your task is to create a set of Java classes to model different types of boxes: a generic **Box**, a specialized **Cube**, and a **Weighted Box**. This problem focuses on applying **inheritance** and **encapsulation** to build a class hierarchy.

Functional Requirements

Technical Requirements

Testing Requirements

Your main method must demonstrate the program works by testing the following scenarios:

  1. Individual Object Tests:
    • Create a `Box` object with dimensions 2x3x4. Print its volume (24).
    • Create a `Cube` object with a side length of 5. Print its volume (125).
    • Create a `WeightBox` object with dimensions 2x3x4 and a weight of 10. Print its volume (24) and weight (10).
  2. Polymorphism Test:
    • Create a List and add one instance of each class (`Box`, `Cube`, and `WeightBox`) to it.
    • Write a `for` loop to iterate through the list. Inside the loop, print the volume of each box. The output should show the correct volume for each object, even though they are all treated as `Box` objects in the list.