Anonymous Inner Classes!

Plain Old VS Argument-Defined!

Foo.java
public interface Foo {
    int foo();
}

Bar.java
public class Bar {
 
    // A Plain Old Anonymous Inner Class! 
    private final Foo foo = new Foo() {
 
        @Override
        public int foo() {
            return 42;
        }
    }; // You need the semicolon!
 
    public int foo() {
        return foo.foo();
    }
 
    public int foo(Foo foo) {
        return foo.foo();
    }
}

App.java
public class App {
    public static void main(String[] args) {
        final Bar bar = new Bar();
        final int var_01 = bar.foo();
 
        // Argument-Defined Anonymous Inner class!
        final int var_02 = bar.foo(new Foo() {
            @Override
            public int foo() {
                return 99;
            }
        }); // No semi colon after `}` which ends the anonymous class definition!
 
        System.out.println(var_01); // Prints 42
        System.out.println(var_02); // Prints 99
    }
}