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
Which functional interface should be used for a lambda with no parameters and no return value?
What is the difference between Consumer and Function functional interfaces?
Which of the following uses method reference correctly?
Which of the following lambda expressions will compile successfully?
What is the output of: BiFunction<Integer, Integer, Integer> add = (a, b) -> a + b; System.out.println(add.apply(5, 3));
In the lambda expression (x) -> x < 10 && x > 0, what is the parameter type?
Which of the following statements about variable scope in lambda expressions is TRUE?
What is the result of this code? UnaryOperator<Integer> square = x -> x * x; System.out.println(square.apply(5));
Which of the following best describes a functional interface?
What will be the output of: Supplier<String> greeting = () -> "Hello"; System.out.println(greeting.get());
Consider: Comparator<String> comp = (s1, s2) -> s2.compareTo(s1); What does this lambda expression do?
Which lambda expression is equivalent to the method reference Integer::parseInt?
What is the correct way to chain lambda expressions using Function interface? Function<Integer, Integer> f1 = x -> x * 2; Function<Integer, Integer> f2 = x -> x + 5; How to apply f1 first, then f2?
Analyze: What is the output? BiConsumer<String, String> printer = (a, b) -> System.out.println(a + b); printer.accept("Java", "8");
Which of the following is a valid functional interface that can be used with lambda expressions?
What is the return type of a lambda expression (x, y) -> x + y where x and y are integers?
Which annotation is used to mark an interface as a functional interface in Java?
Consider a lambda expression: (String s) -> s.length(). What is the correct functional interface for this?
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?
Which of the following lambda expressions is syntactically incorrect?