Exams Knowledge Hub

MCQs for Competitive Exams, School & College Exams

Module: | Arrays, Strings & Exception Handling

Q63: Consider the following statements regarding standard Functional Interfaces (java.util.function):

1. The Predicate\ interface takes a single input argument and strictly returns a boolean result, heavily utilized for evaluating conditions and filtering Streams.
2. The Consumer\ interface accepts a single input argument but returns no result, commonly utilized in forEach iteration blocks to perform side-effect operations.
3. The Supplier\ interface accepts exactly one input argument and transforms it, returning a brand new object of type T back to the caller.

Which of the above statements is/are correct?
A
Only 1 and 2
B
Only 1 and 3
C
Only 2 and 3
D
1, 2, and 3
✅ Correct Answer: A
🎯 Quick Answer:
The correct combination is 1 and 2. Statement 3 is incorrect because the Supplier\ interface strictly accepts NO arguments; it simply generates or provides a result (e.g., T get()). The interface responsible for taking one argument and transforming it into another object is the Function\ interface.
Concept Definition: The java.util.function package provides out-of-the-box functional interfaces designed specifically to act as standard targets for lambda expressions across the Java ecosystem.
Structural Breakdown: Predicate utilizes boolean test(T t). Consumer utilizes void accept(T t). Supplier utilizes T get(). Function utilizes R apply(T t). Historical/Related Context: Prior to Java 8, framework developers constantly had to write their own custom interfaces for generic tasks (e.g., creating an Action interface just to pass a block of code). Oracle standardized these four primary archetypes to unify enterprise APIs and prevent structural fragmentation across the language.
Causal Reasoning: By universally standardizing interfaces like Predicate, the entire Streams API could be built securely.
The Stream.filter() method mathematically guarantees it will only accept a Predicate, ensuring the compiler can strictly enforce that the passed lambda expression will definitely return a boolean capable of deciding whether an element is kept or discarded.