interface Book{
public default String getId(){
return "ISBN123456";
}
}
interface Encyclopedia extends Book{
//INSERT CODE HERE
}
One of the explanation states that:
You cannot override a static method with a non-static method. You can, however, redeclare a static method of a super interface as a default method in the sub interface.
I think the correct phrase would be "You cannot override a default method with a static method."
Hello enthuware,
I'm not able to update my question bank to latest version.
Both from Study view > Question bank and Tools > Check for question bank update
I have the latest ets viewer
If multiple minor corrections reported during a small time frame, they are all applied together and then the version number is updated. This is done to ensure that users are not annoyed by too many update notifications in a short span.
If a critical error is fixed (such as a wrong answer to a question), we apply the fix, update the version number and release the new question bank file immediately.
So, in this case, the fix has been applied but the version number will be updated soon.
If you like our products and services, please help us by posting your review here.
Hi, a couple of the answers talk about redeclaring default methods. Isn't redeclaring (and hiding the original method) only for static methods? I tested different scenarios with the @Override-annotation and it seems to be in agreement with this.
Well, it's a general question actually; can a default method in an interface be redecleared in an extending interface? I thought it can only be overridden.
The following code is one of the correct answers and it is referred to as a redeclaration. Isn't it an override?
Well, redeclaration is a non technical term. Technically meaningful terms would be overriding and hiding. Redeclaration just implies having the same method being present in a sub type. Whether that constitutes a valid override or a valid hiding depends on the situation.
From that perspective, I think yes, you can redeclare a default method of an interface in the sub-interface.
If you like our products and services, please help us by posting your review here.
No, the reason it compiles is because all methods defined in an interface are public by default, unless they are explicitly defined as private. So, the default method in the given problem statement didn't change visibility. It is public even though not defined as public implicitly.
If you like our products and services, please help us by posting your review here.