An anonymous class with three methods

Report a typo

There is an interface:

interface ThreeMethodsInterface {
    
    void do1();
    
    void do2();
    
    void do3();
}

You should create an anonymous class that implements the given interface and assign the instance to the variable instance. The anonymous class must override all methods. The overridden methods do1, do2, do3 must output strings "Implemented do1", "Implemented do2", "Implemented do3" respectively to the standard output. Each output should be on a new line.

Write a program in Java 17
public class Main {

public static void main(String[] args) {

ThreeMethodsInterface instance = /* create an instance of an anonymous class here,
do not forget ; in the end */

instance.do1();
instance.do2();
instance.do3();
}
}

interface ThreeMethodsInterface {

void do1();

void do2();

void do3();
}
___

Create a free account to access the full topic