Question 1
What is the output of the following program? ```java import java.util.function.Predicate; public class Main { static String check(int n, Predicate<Integer> p) { return p.test(n) ? "pass" : "fail"; } public static void main(String[] args) { System.out.println(check(4, n -> n % 2 == 0)); } } ```
A. fail
"fail" is the ternary's branch for a false predicate, but 4 % 2 == 0 is true, so the method returns "pass" instead.
B. passCorrect answer
The lambda supplies the Predicate target type for the parameter, and 4 % 2 == 0 is true, so the ternary maps the boolean to "pass".
C. Compilation fails because a lambda cannot be a method argument
Passing a lambda where a Predicate parameter is expected is the standard target-typing pattern; the parameter supplies the type, so this compiles rather than failing.
D. true
The method never prints the raw boolean; its ternary converts the predicate result into the word "pass" or "fail", so "true" is never output.
Explanation
Passing a lambda where a Predicate parameter is expected is the standard pattern (ruling out `Compilation fails because a lambda cannot be a method...`) — the parameter supplies the target type. 4 % 2 == 0 is true, so check returns "pass" (the ternary maps the boolean to a word — `true` prints the raw boolean, which never happens here).