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
- Define
default void greet()inGreeterinterface (printsHello!) BasicGreeterimplements Greeter (uses default method as-is)FormalGreeterimplements Greeter, overrides greet() to printGood day!- 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