Java OCA OCP Practice Question 1504

Question

Which of the following is a valid lambda expression?

  • A. r -> {return 1==2}
  • B. (q) -> true
  • C. (x,y) -> {int test; return test>0;}
  • D. a,b -> true


B.

Note

Option A is incorrect because the lambda expression is missing a semicolon (;) at the end of the return statement.

Option C is incorrect because the local variable test is used without being initialized.

Option D is also incorrect.

The parentheses are required on the left-hand side of the lambda expression when there is more than one value or a data type is specified.

Option B is the correct answer and the only valid lambda expression.




PreviousNext

Related