Implement a default method

Report a typo

Define and implement a default method print in the Printer interface to make code in the main method print the text This is a default message. Do not change either Main or ConsolePrinter classes.

Write a program in Java 17
// do not change code below
class Main {
public static void main(String... args) {
Printer printer = new ConsolePrinter();
printer.print(); // prints: This is a default message
}
}

class ConsolePrinter implements Printer {
}

interface Printer {
// define and implement default method print to make code above print the message: "This is a default message"
}
___

Create a free account to access the full topic