Oracle Certified Professional Java Se 8 Programmer · Free Practice Question Easy

Question 9

Given code of Test.java file:

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

  • A Runtime Exception
  • B Compilation error
  • C 1020
  • D 30
Reveal correct answer

Correct answer: D

Explanation

If a generic method is defined in a non-generic class then type parameters must appear before the return type of the method.


Integer is also a final class so parameters X and Y can only be of Integer type.


add(10, 20); => Auto-boxing converts int literals to Integer objects. 30 is printed on to the console.

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