ProgrammingModerateProduct-company placement · Java

What is printed?

What is printed?
System.out.print(Stream.of(1, 2, 3).reduce(10, Integer::sum));
  1. A. 16
  2. B. 6
  3. C. 10
  4. D. 60

Correct answer: A. 16

reduce(identity, op) starts from the identity and folds every element in: 10 + 1 + 2 + 3. (10 is not a true identity for +, which would matter for parallel streams.)

More OOP with C++ and Java questions

Exams that ask this topic