Hallo zusammen,
ich habe mal eine kleine theoretische Frage. Durch "default" Methoden gibt es ja bekanntlich bei folgenden Code die Fehlermeldung "Duplicate default methods named func with the parameters () and () are inherited from the types Test.I2 and Test.I1":
Warum gibt es aber bei folgendem Code keine Fehlermeldung? Warum gewinnt dort die Methode von "Both"?
ich habe mal eine kleine theoretische Frage. Durch "default" Methoden gibt es ja bekanntlich bei folgenden Code die Fehlermeldung "Duplicate default methods named func with the parameters () and () are inherited from the types Test.I2 and Test.I1":
Java:
public class Test {
interface I1 {
default public int func() {
return 2;
}
}
interface I2 {
default public int func() {
return 3;
}
}
static class ClassA implements I1,I2 {
}
}
Java:
public class Test {
interface I1 {
default public int func() {
return 2;
}
}
interface I2 {
default public int func() {
return 3;
}
}
interface Both extends I1,I2 {
default public int func() {
return 4;
}
}
static class ClassB implements I1,Both {
}
public static void main(String[] args) {
ClassB obj = new ClassB();
System.out.println(obj.func());
}
}