Java OCA OCP Practice Question 2119

Question

Choose the correct option based on this code segment:.

IntStream.rangeClosed(1, 1).forEach(System.out::println);
  • a . it prints: 1
  • B. it crashes by throwing a java.lang.UnsupportedOperationException
  • C. it crashes by throwing a java.lang.StackOverflowError
  • d. it crashes by throwing a java.lang.IllegalArgumentException
  • e. this program terminates normally without printing any output in the console


A.

Note

the rangeClosed(startValue, endValueInclusiveOfEnd) method generates a sequence of integers starting with startValue till (and inclusive of) endValueInclusiveOfEnd.
hence the call IntStream.rangeClosed(1, 1) results in a stream with only one element and the foreach() method prints that value.



PreviousNext

Related