010-002-005

Overloading: Distinction by Parameter Count

Medium

Problem Description

Overloading: Distinction by Parameter Count

Learning Objective

Learn method overloading with different number of parameters.

Problem

In this problem, you will create a program that implements two overloaded greet methods displaying different greeting messages based on the number of arguments, and displays the result to standard output.

Create the greet method in two versions:

  • greet() (no arguments): displays "Hello!"
  • greet(String name) (with name): displays "Hello, [name]!"

First call greet() with no arguments, then call greet(name) with the name read from standard input.

Input

Line 1: Name (string)

Output

Default: Hello!
Custom: Hello, [name]!

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