Java OCA OCP Practice Question 1705

Question

What is the output of the following?

1:   package mypkg;
2:   import java.util.stream.*;
3:
4:   public class Main {
5:      public static void main(String[] args) {
6:         IntegerStream pages = IntegerStream.of(200, 300);
7:         IntegerSummaryStatistics stats = pages.summaryStatistics();
8:         long total = stats.getSum();
9:         long count = stats.getCount();
10:        System.out.println(total + "-" + count);
11:     }// ww  w.j a v a2s  .c  om
12:  }
  • A. 500-0
  • B. 500-2
  • C. The code does not compile.
  • D. The code compiles but throws an exception at runtime.


C.

Note

For the primitive stream that contains the int primitives, the interface names are incorrect.

They should be IntStream and IntSummaryStatistics, making Option C correct.

If this was fixed, Option B would be the answer.




PreviousNext

Related