Java Programming
Java OOP, collections, multithreading
958 Questions 10 Topics Take Test
Advertisement
Showing 101–110 of 958 questions
What is the return type of the lambda expression: (a, b) -> a > b?
A int
B boolean
C void
D Cannot be determined
Correct Answer:  B. boolean
EXPLANATION

The expression uses comparison operator (>), which returns a boolean value.

Take Test
A lambda expression can only be used with which type of interface?
A Regular interface
B Functional interface with single abstract method
C Interface with multiple abstract methods
D Interface with default methods only
Correct Answer:  B. Functional interface with single abstract method
EXPLANATION

Lambda expressions can only be assigned to functional interfaces that have exactly one abstract method.

Take Test
Which of the following is a valid lambda expression in Java?
A () -> System.out.println("Hello")
B (int x, int y) -> { return x + y; }
C (String s) -> s.length()
D All of the above
Correct Answer:  D. All of the above
EXPLANATION

All three are valid lambda expression syntaxes with different parameter types and return statements.

Take Test
Q.104 Medium Lambda Expressions
What will be the output of: List list = Arrays.asList(1, 2, 3); list.replaceAll(x -> x * 2); System.out.println(list);
A [1, 2, 3]
B [2, 4, 6]
C [] (empty list)
D [2, 2, 2]
Correct Answer:  B. [2, 4, 6]
EXPLANATION

replaceAll() with a lambda expression modifies the list in-place, multiplying each element by 2. Result is [2, 4, 6].

Take Test
Which stream operation would you use to transform elements from one type to another?
A filter()
B map()
C forEach()
D collect()
Correct Answer:  B. map()
EXPLANATION

map() is the intermediate operation used to transform elements from one type/value to another. It applies a function to each element.

Take Test
What is the purpose of the @FunctionalInterface annotation in Java?
A To indicate an interface can be used with lambda expressions
B To enforce that an interface has exactly one abstract method
C To improve performance of lambda expressions
D To allow multiple lambda expressions in one interface
Correct Answer:  B. To enforce that an interface has exactly one abstract method
EXPLANATION

@FunctionalInterface is a compile-time check that ensures an interface has exactly one abstract method, making it safe for lambda implementation.

Take Test
Consider: Stream.of(1, 2, 3).map(x -> { System.out.println(x); return x * 2; }).collect(Collectors.toList()); What will print?
A 1 2 3
B 2 4 6
C Nothing until the collect operation completes
D 1 2 3 2 4 6
Correct Answer:  A. 1 2 3
EXPLANATION

map() is an intermediate operation. The println executes because collect() is a terminal operation that triggers evaluation. It prints 1, 2, 3 (the original values).

Take Test
Q.108 Medium Lambda Expressions
What happens when a lambda expression references a local variable from its enclosing scope?
A The variable must be explicitly final or effectively final
B The variable is automatically copied into the lambda's scope
C Any variable can be accessed without restrictions
D The variable must be static
Correct Answer:  A. The variable must be explicitly final or effectively final
EXPLANATION

Lambda expressions can only access local variables that are final or effectively final (not reassigned). This ensures thread-safety and consistency.

Take Test
Q.109 Medium Lambda Expressions
Which of the following correctly uses method reference with constructor?
A String::new
B new String::
C String->new
D new::String
Correct Answer:  A. String::new
EXPLANATION

Constructor method references use ClassName::new syntax. String::new refers to the String constructor and can be used wherever a Supplier<String> is expected.

Take Test
Consider: Function curried = a -> b -> a + b; What is this pattern called?
A Higher-order function with currying
B Nested lambda expression
C Function composition
D Stream reduction
Correct Answer:  A. Higher-order function with currying
EXPLANATION

This is a curried function - a higher-order function that takes one argument and returns another function taking the next argument. It transforms multi-argument functions into sequences of single-argument functions.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips