1.

Can a functional interface extend/inherit another interface?

Answer»

A functional interface cannot EXTEND another interface with ABSTRACT methods as it will void the rule of ONE abstract METHOD per functional interface. E.g:

interface Parent { public int parentMethod(); } @FunctionalInterface // This cannot be FunctionalInterface interface Child extends Parent { public int childMethod(); // It will also extend the abstract method of the Parent Interface // Hence it will have more than one abstract method // And will give a compiler error }

It can extend other interfaces which do not have any abstract method and only have the DEFAULT, static, another class is overridden, and normal methods. For eg:

interface Parent { public void parentMethod(){ System.out.println("Hello"); } } @FunctionalInterface interface Child extends Parent { public int childMethod(); }


Discussion

No Comment Found