Lambda Expressions
1.Which of the following is the correct syntax for a simple lambda expression that takes an integer and returns its square?
-
A. (int x) -> { return x * x; }
-
B. x -> x * x
-
C. function(x) { return x * x; }
-
D. lambda x: x * x
x -> x * x
x -> x * x
2.Lambda expressions in Java are essentially:
-
A. Anonymous classes that implement a single method.
-
B. Named methods that can be passed as arguments.
-
C. Primitive data types.
-
D. Objects that store multiple methods.
Anonymous classes that implement a single method.
Anonymous classes that implement a single method.
3.What is the main benefit of using lambda expressions?
-
A. They make code more verbose and less readable.
-
B. They allow for functional programming style and more concise code.
-
C. They replace traditional class definitions entirely.
-
D. They are only used for asynchronous operations.
They allow for functional programming style and more concise code.
They allow for functional programming style and more concise code.
4.A lambda expression can only be used with a:
-
A. Class with multiple abstract methods.
-
B. Interface with multiple concrete methods.
-
C. Functional interface.
-
D. Abstract class.
Functional interface.
Functional interface.
5.Which Java version introduced lambda expressions?
-
A. Java 7
-
B. Java 8
-
C. Java 9
-
D. Java 11
Java 8
Java 8