All abstract, default, and static methods in an interface are implicitly public. void export() has not a package-private access. It is implicitly public. Answer is D. The other typo are not delibarely generated I think.
Answer is D.
"Tool::export" is printed and java.lang.IllegalAccessError error is thrown.
Although there is a print on the terminal, this error is classified as a compilation error, according to oracle documentation.
https://docs.oracle.com/javase/8/docs/api/java/lang/IllegalAccessError.html
To test:
interface Exportable {
void export();
}
class Tool implements Exportable {
protected void export () { // line n1 - throwIllegalAccessError
System.out.println("Tool::export");
}
}
class ReportTool extends Tool implements Exportable {
public void export () { // line n2
System.out.println("RTool::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();
}
}
Guys, in my case, testing here at bluej, I verified that the problem is in the interface, marking the Void with a capital v, in this case, the compilation of line n1 and n2 fails. So what convinced me the most was the answer "E".
Void (uppercase):
It is a class in Java that is part of the java.lang package.
It is used as a generic type to indicate that a generic method doesn't return any value.
It is typically used in contexts where generic types are needed, such as in Callable<Void> or in generic classes that can work with different data types, including Void.
It should not be confused with the use of void in method signatures.
Answer - D
Access modifier of the implementation method in child class either has to be same or higher. In this scenario public. NOT protected.
public void export(){
System.out.println("Tool: Export");
}
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.
letmein2
Highly Voted 4 years, 3 months agoamit_lad88
Most Recent 3 days, 21 hours agoakbiyik
1 year agocarloswork
1 year, 1 month agoWinston123
1 year, 6 months agolnrdgst
1 year, 10 months agoManuTov
3 months, 3 weeks agoSurendra88
2 years, 4 months agosarou89
2 years, 8 months agoonyddimmav4576
3 years agoSamAru
3 years, 5 months agorasifer
4 years, 5 months ago