Java Lambda Expression MCQs with answers Page - 8

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. What is the syntax to implement a `Runnable` using a lambda?

  • (A) () -> System.out.println("Run")
  • (B) (String s) -> System.out.println(s)
  • (C) x -> System.out.println(x)
  • (D) (int x, int y) -> x + y

A

Admin • 825.56K Points
Coach

Q. Which lambda expression can be used to check if a string is empty?

  • (A) s -> s.isEmpty()
  • (B) () -> isEmpty()
  • (C) s => s.empty()
  • (D) s -> s.size() == 0

A

Admin • 825.56K Points
Coach

Q. Lambda expressions were primarily introduced to support which Java feature?

  • (A) Object-oriented programming
  • (B) Generic programming
  • (C) Functional programming
  • (D) Procedural programming

A

Admin • 825.56K Points
Coach

Q. What will `() -> System.out.println("Hi")` produce?

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

A

Admin • 825.56K Points
Coach

Q. What kind of interface is necessary for a lambda to be used?

  • (A) Interface with static methods only
  • (B) Functional interface with one abstract method
  • (C) Any abstract class
  • (D) Any interface

A

Admin • 825.56K Points
Coach

Q. Can lambda expressions implement default methods in interfaces?

  • (A) Yes
  • (B) No
  • (C) Only in abstract classes
  • (D) Only static methods

A

Admin • 825.56K Points
Coach

Q. What will be the output of `(x, y) -> x * y` for inputs 3 and 4?

  • (A) 7
  • (B) 12
  • (C) 1
  • (D) 0

A

Admin • 825.56K Points
Coach

Q. Which functional interface should be used to replace a for-each loop with a lambda?

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

A

Admin • 825.56K Points
Coach

Q. In which Java version were method references introduced along with lambdas?

  • (A) Java 6
  • (B) Java 7
  • (C) Java 8
  • (D) Java 9
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