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

Question 47

Question ID: UKOCP27389


Given code:


What will be the result of compiling and executing Test class?

  • A Compilation error
  • B Runtime error
  • C GO FOR IT
  • D LET IT BE
Reveal correct answer

Correct answer: A

Explanation

UKOCP27389:

Anonymous inner class allows to define methods not available in its super class. Anonymous inner class in this case doesn't override the method of super class but it provides a new method Log [L in upper case].


obj is of Logger type, obj.Log(); statement tries to invoke the Log() method of Logger class, which is not available and hence it causes compilation error.

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