Java Lambda Expression MCQs with answers Page - 6

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.01K Points
Coach

Q. Which Java keyword is used to ensure an interface is functional?

  • (A) abstract
  • (B) interface
  • (C) @FunctionalInterface
  • (D) static

A

Admin • 832.01K Points
Coach

Q. Can lambdas access static variables of the enclosing class?

  • (A) Yes
  • (B) No
  • (C) Only if final
  • (D) Only if declared inside the lambda

A

Admin • 832.01K Points
Coach

Q. Which of the following is a valid method reference to an instance method?

  • (A) ClassName::methodName
  • (B) objectName::methodName
  • (C) new::methodName
  • (D) Class::new

A

Admin • 832.01K Points
Coach

Q. What does a lambda like `(x, y) -> x * y` implement?

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

A

Admin • 832.01K Points
Coach

Q. What restriction is placed on local variables used inside a lambda?

  • (A) They must be static
  • (B) They must be public
  • (C) They must be final or effectively final
  • (D) They must be declared inside the lambda

A

Admin • 832.01K Points
Coach

Q. Which functional interface consumes two input arguments and returns no result?

  • (A) BiConsumer
  • (B) BiFunction
  • (C) Predicate
  • (D) Function

A

Admin • 832.01K Points
Coach

Q. How many abstract methods can a functional interface contain?

  • (A) Only one
  • (B) Two
  • (C) Any number
  • (D) None

A

Admin • 832.01K Points
Coach

Q. What will be the output of `(a, b) -> a - b` for inputs 5 and 3?

  • (A) 2
  • (B) 8
  • (C) 15
  • (D) 1

A

Admin • 832.01K Points
Coach

Q. Which interface is designed to accept a value and produce no result?

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

A

Admin • 832.01K Points
Coach

Q. Which interface is used to implement a lambda that takes two arguments and returns a boolean?

  • (A) BiConsumer
  • (B) BiFunction
  • (C) BiPredicate
  • (D) Predicate
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