Java Lambda Expression MCQs with answers Page - 7

You will find multiple-choice questions (MCQs) related to #Java Lambda Expression here. Go through these questions to prepare effectively for your upcoming exams and interviews.

To view the correct answer for any question, simply click the "Show Answer" button.

Have a question to share? Click on "Add Question" to contribute!

A

Admin • 832.27K Points
Coach

Q. Which of the following is a correct lambda expression with no parameters that returns 100?

  • (A) () -> 100
  • (B) (x) -> 100
  • (C) x -> 100
  • (D) () => 100

A

Admin • 832.27K Points
Coach

Q. Which lambda expression will reverse a given string 's'?

  • (A) s -> new StringBuilder(s).reverse().toString()
  • (B) s -> s.reverse()
  • (C) s -> s.revert()
  • (D) s => reverse(s)

A

Admin • 832.27K Points
Coach

Q. What does the following lambda expression represent: `x -> x % 2 == 0`?

  • (A) Checks if a number is odd
  • (B) Checks if a number is even
  • (C) Always returns true
  • (D) Returns the same number

A

Admin • 832.27K Points
Coach

Q. Can a lambda expression return a value?

  • (A) Yes, always
  • (B) Only if it is a Predicate
  • (C) No, lambdas can't return values
  • (D) Only if the return type is void

A

Admin • 832.27K Points
Coach

Q. What is the type of `x -> x.toUpperCase()` if x is a String?

  • (A) Predicate<String>
  • (B) Function<String, String>
  • (C) Consumer<String>
  • (D) Supplier<String>

A

Admin • 832.27K Points
Coach

Q. Which of the following can lambda expressions NOT directly implement?

  • (A) Runnable
  • (B) Comparator
  • (C) Predicate
  • (D) Serializable

A

Admin • 832.27K Points
Coach

Q. What is the role of parentheses in lambda expressions?

  • (A) To wrap the body
  • (B) To enclose parameters
  • (C) To declare return type
  • (D) To define exceptions

A

Admin • 832.27K Points
Coach

Q. Can lambda expressions contain loops?

  • (A) No
  • (B) Yes, in the body if braces are used
  • (C) Only while loops
  • (D) Only for-each loops

A

Admin • 832.27K Points
Coach

Q. What is the purpose of method references like `String::length`?

  • (A) To create a new object
  • (B) To call constructors
  • (C) To refer to an existing method
  • (D) To define a variable

A

Admin • 832.27K Points
Coach

Q. Which functional interface represents a function that returns a value of type T and takes no arguments?

  • (A) Supplier<T>
  • (B) Function<T,R>
  • (C) Consumer<T>
  • (D) Predicate<T>
What's Tag

As you may know, questions are organized under broad categories. Each category can include various types of questions. For example, the "History" category might contain questions about the Revolt of 1857, Shivaji Maharaj, Ancient History, Buddhism, and more.

To further refine this organization, we've introduced tags, which act as sub-categories to group questions more specifically.

Verified users can add tags to any question. If you have any suggestions regarding this system, we'd love to hear from you. Contact Us

Learn More