Question 20
Back to Exercise
What is the output of the following Java program?
import java.util.function.BiFunction;
public class Main {
public static void main(String[] args) {
BiFunction<String, Integer, String> a = (s, n) -> s.repeat(n);
BiFunction<String, Integer, String> b = (var s, var n) -> s.substring(0, n);
BiFunction<String, Integer, String> c = (String s, Integer n) -> s.charAt(n) + "";
System.out.println(a.apply("ab", 2) + " " + b.apply("lambda", 3) + " " + c.apply("java", 1));
}
}
- A abab lam a Correct
- B ab2 lam a
- C abab lamb j
- D Compilation error
Correct Answer: Option A
Implicit, var and explicit parameter types are all allowed – as long as one lambda does not mix them.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!