010-002-010

Emulating Default Values

Hard

Problem Description

Emulating Default Values

In this problem, you will create a program that implements two overloaded power(int base) and power(int base, int exponent) methods to emulate default parameter values, and displays the results to standard output.

Learning Objective: Understand how to achieve default values using overloading

Overview

Use overloading to implement default values when arguments are omitted.

Specifications

  • power(int base) method: returns square (default exponent is 2)
  • power(int base, int exponent) method: returns base^exponent
  • Call power(3) and power(2, 4)

Output Format

3^2 = 9
2^4 = 16

Ready to Try Running Code?

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

Don't have an account?