Oracle Certified Professional Java Se 11 Developer · Free Practice Question Hard

Question 74

Question ID: UKOCP42179


Given code of LogHelper.java file:


Which of the following changes, done independently, allows the code to compile and on execution prints LogHelper-help?

Select 3 options.

  • A Remove the private modifier from the num variable of LogHelper class
  • B Remove the protected modifier from the operation variable of LogHelper class
  • C Remove the protected modifier from the help() method of Helper class
  • D Add the protected modifier to the log() method of Helper class
  • E Add the protected modifier to the help() method of LogHelper class
  • F Add the public modifier to the help() method of LogHelper class
  • G

    Add the public modifier to the log() method of LogHelper class

  • H

    Add the protected modifier to the log() method of LogHelper class

Reveal correct answers

Correct answers: C, E, F

Explanation

UKOCP42179:

Let us first find out the issue:

As instance variables are hidden by subclasses and not overridden, hence overriding rules are not for the instance variables. There are no issues with variables 'num' and 'operation'.

log() method is declared with default modifier in both the classes, hence no issue with log() method as well.

abstract method help() is declared with protected modifier in Helper class and in LogHelper class, it is overridden with default modifier and this causes compilation error. So below solutions to resolved this issue:

1. Remove the protected modifier from the help() method of Helper class: Both the overridden and overriding methods will have same default modifier, which is allowed

OR

2. Add the protected modifier to the help() method of LogHelper class: Both the overridden and overriding methods will have same protected modifier, which is allowed

OR

3. Add the public modifier to the help() method of LogHelper class: Overridden method will have protected modifier and overriding method will have public modifier, which is allowed

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need