NBKRIST Java Hub

← Back to Exam Panel

Problem Statement: Geometric Shapes

Your task is to create a set of Java classes to model different 2D shapes (Square, Rectangle, Triangle) and calculate their area and volume. This problem focuses on applying three key OOP concepts: **Interfaces**, **Abstract Classes**, and **Polymorphism**.

Functional Requirements

Technical Requirements

Testing Requirements

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

  1. Individual Shape Test:
    • Create a `Square` object with a side length of 5. Print its calculated area (25) and volume (0).
    • Create a `Rectangle` object with a length of 4 and a width of 6. Print its calculated area (24) and volume (0).
    • Create a `Triangle` object with a base of 8 and a height of 5. Print its calculated area (20) and volume (0).
  2. Polymorphism Test:
    • Create a List and add the three objects you created above.
    • Write a `for` loop to iterate through the list. Inside the loop, print the area and volume of each shape. The output should show the correct area for each shape in the list, demonstrating dynamic method dispatch.