QuestionQ219

Working with Inheritance

Given these code fragments:

Question Image

What is the outcome?

  • A Compilation fails only at line n1.
  • B Compilation fails only at line n2.
  • C Tool::export Tool::export
  • D Compilation fails at both line n1 and line2.
  • E RTool::export Tool::export
Explanation

A method declared in an interface is implicitly public. Tool.export() correctly implements it as public, but ReportTool.export() attempts to override that method with package-private access. An overriding method cannot reduce the access level of the inherited method, so compilation fails at line n2.

Community Discussion

No comments yet. Be the first to start the discussion!