Single method

Report a typo

There is an interface:

interface SingleMethodInterface {
    
    void doSomething();
}

You should create an anonymous class that implements the given interface and assign the instance to the variable instance. The anonymous class must override the method doSomething so that it outputs "The anonymous class does something" to the standard output.

Use the provided code template, do not copy the interface to the code.

Write a program in Java 17
public class Main {

public static void main(String[] args) {

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

instance.doSomething();
}
}

interface SingleMethodInterface {

void doSomething();
}
___

Create a free account to access the full topic