Java Lambda Expression MCQs with answers Page - 4

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 annotation helps in identifying a functional interface?

  • (A) @FunctionalInterface
  • (B) @Override
  • (C) @Lambda
  • (D) @Functional

A

Admin • 825.56K Points
Coach

Q. Which statement is true about lambdas and anonymous classes?

  • (A) Both can have multiple methods
  • (B) Lambdas have less boilerplate code than anonymous classes
  • (C) Lambdas can extend classes
  • (D) Anonymous classes are faster than lambdas

A

Admin • 825.56K Points
Coach

Q. Which of the following is a valid lambda expression that accepts two integers and returns their sum?

  • (A) (int a, int b) -> a + b
  • (B) (a, b) => a + b
  • (C) a, b -> a + b
  • (D) (a, b): a + b

A

Admin • 825.56K Points
Coach

Q. Can lambdas be used to replace anonymous inner classes that implement listeners in GUI?

  • (A) Yes
  • (B) No
  • (C) Only in Swing
  • (D) Only in JavaFX

A

Admin • 825.56K Points
Coach

Q. In which scenario is using a lambda not possible?

  • (A) When implementing Runnable
  • (B) When implementing Comparator
  • (C) When implementing an interface with multiple abstract methods
  • (D) When using Stream API

A

Admin • 825.56K Points
Coach

Q. Which Stream API method is commonly used with lambdas?

  • (A) map()
  • (B) start()
  • (C) execute()
  • (D) invoke()

A

Admin • 825.56K Points
Coach

Q. What is the default behavior of variables captured in lambdas?

  • (A) They must be mutable
  • (B) They must be final or effectively final
  • (C) They can be reassigned
  • (D) They are ignored

A

Admin • 825.56K Points
Coach

Q. What is the purpose of method references in the context of lambdas?

  • (A) To create a new interface
  • (B) To refer to methods directly as a lambda alternative
  • (C) To override methods
  • (D) To convert lambdas to strings

A

Admin • 825.56K Points
Coach

Q. Which of the following functional interfaces is used to perform operations on primitive int values?

  • (A) IntConsumer
  • (B) IntFunction
  • (C) IntPredicate
  • (D) All of the above

A

Admin • 825.56K Points
Coach

Q. What does a lambda expression represent in Java?

  • (A) An object
  • (B) An instance of a functional interface
  • (C) A class
  • (D) A 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