010-002-011

Overloading by Parameter Count

Easy

Problem Description

Overloading by Parameter Count

In this problem, you will create a program that overloads the calculateArea method with two versions having different parameter counts, calculates the areas of a square and a rectangle, and displays the results to standard output.

Learning Objective: Understand how to overload methods by varying the number of parameters

Overview

In method overloading, methods with different parameter counts can have the same name. This allows designing flexible APIs with optional parameters.

Specifications

  • Define two calculateArea methods:
    • calculateArea(double side): square area (side * side)
    • calculateArea(double width, double height): rectangle area (width * height)
  • Display results from each method

Output Format

Square area: 25.0
Rectangle area: 24.0

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?

Sign Up