Answer is B.
"You cannot reducing de visibility of the method export, in class ReportTool."
To test:
interface Exportable {
void export();
}
class Tool implements Exportable {
public void export () { // line n1
System.out.println("Tool::export");
}
}
class ReportTool extends Tool {
void export() { // line n2
System.out.println("Tool::export");
}
public static void main(String[] args) {
Tool aTool = new ReportTool();
Tool bTool = new Tool();
callExport(aTool);
callExport(bTool);
}
public static void callExport(Exportable ex ) {
ex.export();
}
}
The answer is letter B.
N1 -> Any method by default inside an interface (Even without evidence) is public. Already in a class that implements an interface the public has to be put, because a method that was inherited cannot have a lower range, as put public it compiles.
N2 -> It doesn't compile, because as the method was not put public, it has its visibility in default because it is inside a class and the default visibility is lower than the public of the interface, making the code not compile.
Answer is B
n1 is fine as the interface method is assumed public
n2 attempts to reduce visibility
upvoted 2 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
MPignaProTech
2 months, 3 weeks agoakbiyik
2 years, 1 month agocarloswork
2 years, 2 months agoiSnover
2 years, 3 months agoshivkumarx
2 years, 4 months ago