Java Lambda Expression MCQs with answers Page - 5

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 • 825.56K Points
Coach

Q. Which method does the `Runnable` functional interface define?

  • (A) run()
  • (B) execute()
  • (C) apply()
  • (D) start()

A

Admin • 825.56K Points
Coach

Q. Which feature works closely with lambda expressions to facilitate bulk data operations?

  • (A) Generics
  • (B) Collections
  • (C) Streams API
  • (D) Reflection

A

Admin • 825.56K Points
Coach

Q. Which functional interface is commonly used to filter elements in a stream?

  • (A) Predicate
  • (B) Function
  • (C) Consumer
  • (D) Supplier

A

Admin • 825.56K Points
Coach

Q. What does the `Supplier` functional interface represent?

  • (A) Takes input and returns output
  • (B) Takes no input and returns a result
  • (C) Takes input and returns void
  • (D) Returns a boolean result

A

Admin • 825.56K Points
Coach

Q. Which lambda expression syntax is valid to implement a `Consumer<String>` that prints the string?

  • (A) s -> System.out.println(s)
  • (B) (s) => print(s)
  • (C) s :> System.out.print(s)
  • (D) (s) => System.print(s)

A

Admin • 825.56K Points
Coach

Q. Which lambda expression counts the length of a string?

  • (A) s -> s.size()
  • (B) s -> s.length()
  • (C) s -> s.count()
  • (D) s -> s.len()

A

Admin • 825.56K Points
Coach

Q. Can a lambda expression have multiple statements in its body?

  • (A) No
  • (B) Yes, enclosed within curly braces
  • (C) Only if each statement is on a new line
  • (D) Only if using semicolons

A

Admin • 825.56K Points
Coach

Q. What is the output of `Runnable r = () -> System.out.println("Hello"); r.run();`?

  • (A) Compilation error
  • (B) Hello
  • (C) null
  • (D) Nothing

A

Admin • 825.56K Points
Coach

Q. Which functional interface returns a result and may throw an exception?

  • (A) Runnable
  • (B) Callable
  • (C) Consumer
  • (D) Supplier

A

Admin • 825.56K Points
Coach

Q. Which operator is used in method references?

  • (A) ->
  • (B) ::
  • (C) =>
  • (D) **
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