Welcome to the Java Lambda Expressions Coding Quiz. In this quiz, we present 10 coding MCQ questions to test your coding knowledge of the Java Lambda Expressions. Each question has a correct and brief explanation.
1. What is the output of the following Java code snippet?
Runnable r = () -> System.out.println("Hello Lambda!");
r.run();
a) Hello Lambda!
b) Compilation error
c) No output
d) Runtime error
2. What does this Java code snippet output?
Function<Integer, Integer> func = x -> x * x;
System.out.println(func.apply(5));
a) 10
b) 25
c) 30
d) 5
3. Identify the output of the following code:
Predicate<String> isLongerThan5 = s -> s.length() > 5;
System.out.println(isLongerThan5.test("Lambda"));
a) true
b) false
c) Compilation error
d) Runtime error
4. What will be printed by this Java code?
Consumer<String> printer = s -> System.out.println(s.toUpperCase());
printer.accept("lambda");
a) lambda
b) LAMBDA
c) Lambda
d) Compilation error
5. What does this code snippet output?
Supplier<String> stringSupplier = () -> "Java";
System.out.println(stringSupplier.get());
a) Java
b) ""
c) null
d) Compilation error
6. What is the result of executing this code?
BiFunction<Integer, Integer, Integer> adder = (a, b) -> a + b;
System.out.println(adder.apply(10, 5));
a) 15
b) 10
c) 5
d) Compilation error
7. What will the following Java code snippet output?
IntUnaryOperator doubleNumber = x -> x * 2;
System.out.println(doubleNumber.applyAsInt(4));
a) 2
b) 4
c) 8
d) 16
8. What does the following code snippet print?
BinaryOperator<Integer> multiplier = (a, b) -> a * b;
System.out.println(multiplier.apply(3, 7));
a) 10
b) 21
c) 24
d) 30
9. Determine the output of this Java code:
List<String> names = Arrays.asList("Alice", "Bob", "Charlie");
names.forEach(name -> System.out.println(name.toUpperCase()));
a) Alice Bob Charlie
b) alice bob charlie
c) ALICE BOB CHARLIE
d) Alice\nBob\nCharlie
10. What is the result of the following code snippet?
UnaryOperator<String> exclaim = s -> s + "!";
String result = exclaim.apply("Hello");
System.out.println(result);
a) Hello
b) Hello!
c) Hello!!
d) Compilation error
Comments
Post a Comment
Leave Comment