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

Question 95

Question ID: UKOCP66404


Given code:


What is the result?

  • A 15
  • B Runtime Exception
  • C Compilation error
Reveal correct answer

Correct answer: C

Explanation

UKOCP66404:

Generic Stream<T> interface has following methods:

Optional<T> min(Comparator<? super T> comparator);

Optional<T> max(Comparator<? super T> comparator);


Primitive Stream interfaces (IntStream, LongStream & DoubleStream) has methods min(), max(), sum(), average() and summaryStatistics(). 


In this case, as stream is a generic interface, hence stream.sum() 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