In the below code when I am having a class implementing two interfaces with same default method signature it ask me to override it. but in the overriden method why I have to use super keyWord to call the default method.
package practice;
interface interA{
public default void AImp(){
System.out.println("Calling Aimp from interA");
}
}
interface interB{
public default void AImp(){
System.out.println("Calling Aimp from interB");
}
}
public class Practice implements interA,interB {
public static void main(String[] args) {
Practice inter = new Practice();
inter.AImp();
}
@Override
public void AImp() {
interA.super.AImp();
}
}
I can do the same b using below code:
@Override
public void AImp() {
interA inter = new Practice();
inter.AImp();
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…