QuestionQ66

Working with Selected Classes from the Java API

Given the following code fragment:

Question Image

What is the outcome?

  • A Compilation fails.
  • B Hi removed
  • C An UnsupportedOperationException is thrown at runtime.
  • D The program compiles, but it prints nothing.
Explanation

A Java lambda body must be an expression or a block. return s.length() <= 2; is a statement and cannot appear inside parentheses as an expression body. A value-returning lambda using return requires braces around its body, so this code produces a compilation error.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!