Java OCA OCP Practice Question 716


Which of the following can fill in the blank to make the code compile?

import java.util.function.*; 
public class Main { 
   public static void main(String[] s) { 
      Predicate<String> pred = ___ -> true; 
  • A. (Integer i)
  • B. (Object o)
  • C. (String s)
  • D. None of the above



The type in the lambda must match the generic declared on the Predicate.

In this case, that is String.

Options A and B are incorrect.

While Option C is of the correct type, it uses the variable s, which is already in use from the main() method parameter.

None of these are correct, and Option D is the answer.