Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can an anonymous class implement the non abstract method of the abstract class?

Tags:

java

findbugs

Can an Abstract class non abstract method be overridden by using Anonymous class?. The FindBugs tool is issuing " Uncallable method of anonymous class" issue. Please check the below example for more information

public class BaseClass {
    // This class is a Library Class.
}

public abstract class AbstractBaseClass extends BaseClass {
    public abstract void abstractMethod();
    public void nonAbstractMethod() {}
}

public abstract class DerivedAbstractClass extends AbstractBaseClass {
   // Here Some more additional methods has been added
}

public class DemoAbstract {

    public static void main(String[] args) {
        init();
    }

    private static void init() {
        DerivedAbstractClass derivedAbstractClass = new DerivedAbstractClass() {
            @Override
            public void abstractMethod() {

            }

            @Override
            public void nonAbstractMethod() {
                 // Is it possible to override like this?
            }
        };
    }
}
like image 468
Sarath Upadrista Avatar asked Jan 27 '15 08:01

Sarath Upadrista


1 Answers

Yes, this is possible. You can override any non final, non static method

like image 110
nogard Avatar answered Oct 12 '22 13:10

nogard