LearnFrenzy
Sign in Take a free test

Lambda Expressions · Exercise 1 of 4

Lambda Expressions Lambda Expressions MCQ

  • 20 questions
  • Page 1 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Twenty multiple-choice questions on Java lambda expressions: syntax, functional interfaces, java.util.function, method references, capture rules, this, and composition. Pick an option to check your answer instantly.

Question 1 Easy

To which type can a lambda expression be assigned?

A Any class
B A functional interface – an interface with exactly one abstract method
C Object
D Any interface
Question page & discussion
Question 2 Easy

Which is a valid lambda expression?

A x => x * 2
B (a, b) -> a + b
C a, b -> a + b
D -> 5
Question page & discussion
Question 3 Easy

How does a block-body lambda return a value?

A The last expression is returned automatically
B With an explicit return statement
C By assigning to result
D It cannot return values
Question page & discussion
Question 4 Easy

Which functional interface takes a value and returns a boolean?

A Function<T, R>
B Predicate<T>
C Supplier<T>
D Consumer<T>
Question page & discussion
Question 5 Easy

What does a Consumer<T> do?

A Returns a T without input
B Accepts a T and returns nothing
C Converts T to R
D Tests a T
Question page & discussion
Question 6 Easy

Which interface represents () -> T?

A Runnable
B Supplier<T>
C Callable<Void>
D Consumer<T>
Question page & discussion
Question 7 Medium

Which is true of UnaryOperator<T> and BinaryOperator<T>?

A They return boolean
B They are Function<T, T> and BiFunction<T, T, T> where input and output types are the same
C They take no arguments
D They work only with numbers
Question page & discussion
Question 8 Medium

String::toUpperCase used as a Function<String, String> is equivalent to …

A () -> String.toUpperCase()
B s -> s.toUpperCase()
C s -> String.toUpperCase(s)
D new String().toUpperCase()
Question page & discussion
Question 9 Easy

Which is a constructor reference?

A ArrayList::create
B ArrayList::new
C new::ArrayList
D ArrayList.new()
Question page & discussion
Question 10 Medium

Which local variables can a lambda use?

A Any local variable
B Only final or effectively final local variables
C Only static variables
D None
Question page & discussion

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links