About Question enthuware.ocpjp.v8.2.1828 :
Posted: Fri Jan 29, 2016 12:01 pm
A note in the solution to the question tells for an option:
This code snippet demonstrates it:
The colored part is incorrect. There is a way to invoke the default method (which may be useful, e.g., when inheriting two different interfaces with the same method and default implementations, or simply when the default is good enough, just needs some decoration):super.methodName(...) is a valid way to invoke a super class's method from anywhere within a subclass's method. But it works only for classes. You cannot invoke the interface's default method using this technique. In fact, if a class (or an interface) overrides a default method of an interface, there is no way to invoke that default method from that class (or interface).
This code snippet demonstrates it:
Code: Select all
interface Foo {
default void foo() {
}
}
interface Bar extends Foo {
default void foo() {
Foo.super.foo(); // Use the parent interface as the qualifier for 'super'
}
}