017-003-008

Interface Default Methods

Easy

Problem Description

Interface Default Methods

In this problem, you will create a program that defines a default method in the Greeter interface, implements it in BasicGreeter (using the default as-is) and in FormalGreeter (overriding it), and displays the results to standard output.

Learning Objective: Understand defining and using default methods in interfaces

Overview

Define a default method in an interface and verify behavior when an implementing class uses it as-is versus overriding it.

Specifications

  1. Define default void greet() in Greeter interface (prints Hello!)
  2. BasicGreeter implements Greeter (uses default method as-is)
  3. FormalGreeter implements Greeter, overrides greet() to print Good day!
  4. In main, create objects and call greet()

Output Format

Hello!
Good day!

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