Home Subjects Java Programming Lambda Expressions

Java Programming
Lambda Expressions

Java OOP, collections, multithreading

32 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 31–32 of 32
Topics in Java Programming
Which of the following is a valid lambda expression syntax in Java?
A (int x, int y) -> x + y
B (x, y) => x + y
C [x, y] -> x + y
D (x, y) : x + y
Correct Answer:  A. (int x, int y) -> x + y
EXPLANATION

Valid Java lambda syntax uses arrow operator (->). Parameters can be typed or untyped, and the expression or block follows the arrow.

Test
What is the primary purpose of lambda expressions introduced in Java 8?
A To provide a concise syntax for implementing functional interfaces
B To replace all anonymous inner classes
C To improve memory management
D To simplify exception handling
Correct Answer:  A. To provide a concise syntax for implementing functional interfaces
EXPLANATION

Lambda expressions provide a concise way to implement single abstract method (functional interfaces) without verbose anonymous class syntax.

Test
IGET
IGET AI
Online · Exam prep assistant
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips