ProgrammingHardGATE CS · TCS NQT Prime · Product Company SDE
Which java.util.function functional interface best fits a lambda that takes one argument of type T and returns a boolean?
- A. Predicate<T>
- B. Consumer<T>
- C. Supplier<T>
- D. Function<T, R>
Correct answer: A. Predicate<T>
Predicate<T> is specifically defined with a single abstract method `boolean test(T t)`, matching a one-argument, boolean-returning lambda exactly.
More OOP with C++ and Java questions
- A base class method is declared final in Java. What does this guarantee about calls to it through a base-class reference, regardless of…
- cpp struct S { int a, b; S(int x) : b(x), a(b) { } }; int main() { S s(5); cout << s.a << " " << s.b; } Members a and b are declared in…
- What does List<? super Integer> allow, in contrast to List<? extends Integer>?
- java try { throw new ArithmeticException("x"); } catch (RuntimeException e) { System.out.print("R"); } catch (ArithmeticException e) {…
- Which OOP principle bundles data with the methods that act on it and hides the internal state behind an interface?
- In Java, which keyword makes one class inherit from another class?