Java Lambda Expression MCQs with answers Page - 3

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 of these is NOT a characteristic of lambda expressions in Java?

  • (A) They can access final or effectively final variables.
  • (B) They can have multiple abstract methods.
  • (C) They provide concise syntax.
  • (D) They can be used to instantiate functional interfaces.

A

Admin • 825.56K Points
Coach

Q. What is the output type of this lambda: `(String s) -> s.length()`?

  • (A) int
  • (B) String
  • (C) boolean
  • (D) double

A

Admin • 825.56K Points
Coach

Q. Which lambda expression syntax is correct for a function that takes no arguments and returns 5?

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

A

Admin • 825.56K Points
Coach

Q. Which functional interface is used to evaluate conditions with lambda expressions?

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

A

Admin • 825.56K Points
Coach

Q. Which method is provided by the Predicate functional interface?

  • (A) apply()
  • (B) get()
  • (C) test()
  • (D) accept()

A

Admin • 825.56K Points
Coach

Q. What is the result type of `Function<String, Integer>` when applying a lambda like `s -> s.length()`?

  • (A) String
  • (B) Integer
  • (C) Double
  • (D) Boolean

A

Admin • 825.56K Points
Coach

Q. Which of these interfaces does NOT support lambda implementation?

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

A

Admin • 825.56K Points
Coach

Q. What is the main purpose of lambda expressions in Java?

  • (A) To create classes dynamically
  • (B) To reduce code verbosity in implementing functional interfaces
  • (C) To replace constructors
  • (D) To handle exceptions

A

Admin • 825.56K Points
Coach

Q. Which of the following lambda expressions is valid for a `Predicate<Integer>`?

  • (A) x -> x > 10
  • (B) (x, y) -> x + y
  • (C) () -> true
  • (D) (x) -> x.length()

A

Admin • 825.56K Points
Coach

Q. In lambda expression `(a, b) -> a + b`, what is required of 'a' and 'b'?

  • (A) Both must be final
  • (B) Both must be of the same type
  • (C) Both must be numbers
  • (D) Both must be parameters of the same functional interface method
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