iGET

Java Programming - MCQ Practice Questions

Practice free Java Programming multiple-choice questions with detailed answers and explanations. Perfect for competitive exam preparation.

958 questions | 100% Free

Q.421Medium

What happens when a lambda expression references a local variable from its enclosing scope?

Q.422Medium

What will be the output of: List<Integer> list = Arrays.asList(1, 2, 3); list.replaceAll(x -> x * 2); System.out.println(list);

Q.423Medium

Which of the following lambda expressions has incorrect syntax?

Q.424Medium

What will be the type of the lambda expression (x) -> x.toString()?

Q.425Medium

Which functional interface should be used for a lambda with no parameters and no return value?

Q.426Medium

What is the difference between Consumer and Function functional interfaces?

Q.427Medium

Which of the following uses method reference correctly?

Q.428Medium

Which of the following lambda expressions will compile successfully?

Q.429Medium

In the lambda expression (x) -> x < 10 && x > 0, what is the parameter type?

Q.430Medium

Which of the following statements about variable scope in lambda expressions is TRUE?

Q.431Medium

Consider: Comparator<String> comp = (s1, s2) -> s2.compareTo(s1); What does this lambda expression do?

Q.432Medium

Which lambda expression is equivalent to the method reference Integer::parseInt?

Q.433Medium

Analyze: What is the output? BiConsumer<String, String> printer = (a, b) -> System.out.println(a + b); printer.accept("Java", "8");

Q.434Medium

What is the return type of a lambda expression (x, y) -> x + y where x and y are integers?

Q.435Medium

Consider a lambda expression: (String s) -> s.length(). What is the correct functional interface for this?

Q.436Medium

What will happen if you try to access a local variable from an enclosing scope that is not final or effectively final in a lambda expression?

Q.437Medium

Consider the code: List<String> names = Arrays.asList("Alice", "Bob"); names.forEach(name -> System.out.println(name)); What type of functional interface is used in forEach?

Q.438Medium

What is the output of: List<Integer> nums = Arrays.asList(1,2,3); nums.stream().filter(x -> x > 1).forEach(System.out::println);

Q.439Medium

Which lambda expression correctly implements a custom functional interface: public interface Math { int calculate(int a, int b); }

Q.440Medium

Consider: Comparator<Integer> comp = (a, b) -> b - a; List<Integer> list = Arrays.asList(3,1,2); Collections.sort(list, comp); What is the result?