One of the explanations provided when reviewing this question is not clear. I am not saying the explanation is wrong. I am saying it is not clear.
Unclear sentence #1:
"super.methodName(...) is a valid way to invoke a SUPER CLASS's method from anywhere within a subclass's method."
I guess they mean to say that super.methodName(...) is NOT a valid way to invoke an INTERFACE's method from anywhere within a subclass's method.
Unclear sentence #2:
"A class (or an interface) can invoke a default method of an interface that is explicitly mentioned in the class's implements clause (or the interface's extends clause) by using the same syntax i.e. <InterfaceName>.super.<methodName>."
I guess they mean to say that <InterfaceName>.super.<methodName> is a valid way to invoke an interface's method. They confuse this message by unnecessarily repeating trivial information about inheritance syntax of classes and interfaces.
Furthermore, they fail to explain why this <InterfaceName>.super.<methodName> must be used instead of super.<methodName>. This is because multiple inheritance is not possible with classes, but it is with interfaces. Therefore, super.<methodName> is an ambiguous statement when referring to a parent interface -> Which one of the multiple possibilities are you referrring to. The solution -> <InterfaceName>.super.<methodName>
Unclear sentence #3:
"However, THIS technique cannot be used to invoke a default method provided by an interface that is not directly implemented (or extended) by the caller."
The use of a double negative (i.e. "cannot be" and "is not") is confusing.
Also, the pronoun "this" is confusing. Do they mean super.methodName(...) - of which they somewhat explained that it could indeed not be used? Or do they mean <InterfaceName>.super.<methodName> - of which they claimed that it could be used .... but now apparently cannot be used after all!?!?
I guess they mean to say that the technique <InterfaceName>.super.<methodName> can only be used if <InterfaceName> is directly implemented.
About Question enthuware.ocpjp.v8.2.1828 :
Moderator: admin
-
- Posts: 9
- Joined: Wed Jun 30, 2021 6:53 am
- Contact:
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1828 :
The explanation has now been updated as follows:
Thank you for your feedback!
Hope it is clearer now.1. Although super.methodName(...) is a valid way to invoke a super class's method from anywhere within a subclass's method, it is not a valid way to invoke a default method of an interface.
2. A class (or an interface) can invoke a default method of an interface that is explicitly mentioned in the class's implements clause (or the interface's extends clause) by using the syntax <InterfaceName>.super.<methodName>(...).
In other words, the <InterfaceName>.super.<methodName>(...) technique can be used to invoke a default method provided by an interface only if the interface is directly implemented (or extended) by the caller class (or interface).
Here is an example:
interface A {
default void hello() {
}
}
interface B extends A {
default void hello() {
super.hello(); //This is NOT valid.
A.super.hello(); //This is valid.
}
}
public class TestClass implements B {
public void hello() {
super.hello();//This is NOT valid.
A.super.hello(); //This is NOT valid because TestClass does not implement A directly.
B.super.hello(); //This is valid.
}
}
Thank you for your feedback!
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 22 guests