Search Tutorials


Java Lambda Expressions MCQ - Multiple Choice Questions And Answers | JavaInUse

Java Lambda Expressions MCQ - Multiple Choice Questions And Answers

Q. What is a lambda expression in Java?

A. An anonymous function
B. A named function
C. A static function
D. A function with a return type

Q. Which functional interface is used to represent a supplier in Java 8?

A. Consumer
B. Function
C. Supplier
D. Predicate

Q. How are lambda expressions denoted in Java?

A. ->
B. =>
C. <>
D. ::

Q. Which functional interface is used to represent a function that accepts an input and produces a result in Java 8?

A. Consumer
B. Function
C. Supplier
D. Predicate

Q. Which functional interface is used to represent a function that takes an argument and returns a boolean value in Java 8?

A. Consumer
B. Function
C. Supplier
D. Predicate

Q. In the context of Java 8 lambda expressions, what is a target type?

A. The type of the lambda expression
B. The type of the functional interface
C. The type of the argument
D. The return type of the lambda expression

Q. What is the purpose of the Consumer functional interface in Java 8?

A. To produce results
B. To consume values
C. To filter elements based on a condition
D. To transform values

Q. Which functional interface is used to represent a function that doesn't take any arguments but produces a result in Java 8?

A. Consumer
B. Supplier
C. Function
D. Runnable

Q. What is the purpose of the Predicate functional interface in Java 8?

A. To produce results
B. To consume values
C. To filter elements based on a condition
D. To transform values

Q. Which functional interface is used to represent a consumer that takes two input arguments and returns no result in Java 8?

A. BiConsumer
B. BiFunction
C. BiPredicate
D. Comparator

Q. What is a Lambda Expression in Java?

A.
An anonymous function that can be passed around
B.
A predefined function in Java libraries
C.
A static method in Java
D.
An abstract class in Java





Q. Which of the following represents a Lambda Expression in Java?

A.
    (int a, int b) -> a + b
    
B.
    public int add(int a, int b) { return a + b; }
    
C.
    (a, b) => a + b
    
D.
    int sum = (x, y) -> x + y;
    

Q. How do you declare a lambda expression in Java?

A.
    {int x, int y -> x + y}
    
B.
    (int x, int y) -> { return x + y; }
    
C.
    int sum(int x, int y) { return x + y; }
    
D.
    public int add(int a, int b) { a + b; }
    

Q. Which functional interface is provided by Java to represent a function that takes two arguments and produces a result?

A.
    Consumer
    
B.
    Supplier
    
C.
    BiFunction
    
D.
    Predicate
    

Q. What is the operator used in Lambda Expressions to separate parameters from the body?

A.
    ->
    
B.
    ::
    
C.
    -
    
D.
    =>