If I have a class with an abstract method:
abstract class Base {
abstract void foo();
}
and an interface declaring the same method with the default implementation:
interface Inter {
default void foo() {
System.out.println("foo!");
}
}
Do I need to provide an implementation in a class that implements / extends both?
class Derived extends Base implements Inter {
}
This seems to work, but I get a compilation error, which is Derivednot abstract and does not cancel the abstract method foo.
I assume that the abstract method from the class is "more important" than the default method from the interface.
Is there a good way to make this work?
, (A B expand C, D E extend F, C F extend G), . , ,
abstract class C extends G {
abstract void foo();
abstract void bar();
abstract void quz();
void baz() {
foo();
bar();
}
}
abstract class A extends C {
void quz() { }
}
abstract class B extends C {
void quz() { }
}
interface C1 {
default void foo() { }
}
class A1 extends A implements C1 {
@Override void bar() { ... }
}
class B1 extends B implements C1 {
@Override void bar() { ... }
}
interface C2 {
default void foo() { }
}
class A2 extends A implements C2 {
@Override void bar() { ... }
}
class B2 extends B implements C2 {
@Override void bar() { ... }
}