Creating the instance of abstract class or anonymous class

You create an anonymous class that extends your abstract class.

In the snipped below, you are extending AbstractDemo and provide implementations for its abstract methods.

new AbstractDemo() {
    @Override
    void showMessage() {
        // TODO Auto-generated method stub
    }

    @Override
    int add(int x, int y) {
        // TODO Auto-generated method stub
        return 0;
    }
};

Leave a Comment