Java / Interface
How will you call a default method of an interface in a class?
Using super keyword along with interface name.
interface A { default void foo() { System.out.println("A.foo"); } } public class B implements A { @Override public void foo() { System.out.println("B.foo"); } void aFoo() { A.super.foo(); } public static void main(String[] args) { B b = new B(); b.foo(); b.aFoo(); } }
More Related questions...