Computer scienceProgramming languagesJavaCode organizationObject-oriented programmingOther conceptsNested classes

Anonymous classes properties

Create instance

Report a typo

There is an abstract class:

abstract class SuperClass {
    
    public static void method1() {
        System.out.println("It's a static method.");
    }

    public void method2() {
        System.out.println("It's not a static method.");
    }
    
    public abstract void method3();
}

You should create an anonymous class that extends this abstract class and assign it to the variable instance.
The anonymous class should override only methods that can be overridden. Each overridden method must print its name to the standard output on a separate line without parentheses "()".

After that, you should call all the overridden methods in the increasing order.

An example of the output:

method1
method2
...
methodN
Write a program in Java 17
class CreateInstance {

public static SuperClass create() {

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

// call the overridden methods

return instance;
}
}

// Don't change the code below

abstract class SuperClass {

public static void method1() {
System.out.println("It's a static method.");
}

public void method2() {
System.out.println("It's not a static method.");
}

public abstract void method3();
}
___

Create a free account to access the full topic