Functional Interfaces
1.What is a functional interface in Java?
-
A. An interface with no methods at all.
-
B. An interface with exactly one abstract method.
-
C. An interface with multiple abstract methods.
-
D. An interface that extends java.io.Serializable.
An interface with exactly one abstract method.
An interface with exactly one abstract method.
2.Which annotation is commonly used to mark a functional interface (though not strictly required)?
-
A. @Override
-
B. @Deprecated
-
C. @FunctionalInterface
-
D. @interface
@FunctionalInterface
@FunctionalInterface
3.Which of the following is NOT a built-in functional interface in Java?
-
A. Predicate
-
B. Consumer
-
C. Supplier
-
D. Iterator
Iterator
Iterator
4.What is the purpose of the java.util.function.Predicate functional interface?
-
A. To consume an object and return nothing.
-
B. To supply an object.
-
C. To test an object and return a boolean.
-
D. To transform an object from one type to another.
To test an object and return a boolean.
To test an object and return a boolean.
5.Can a functional interface have default and static methods?
-
A. No, it can only have one abstract method.
-
B. Yes, default and static methods do not count towards the single abstract method rule.
-
C. Only static methods, not default methods.
-
D. Only default methods, not static methods.
Yes, default and static methods do not count towards the single abstract method rule.
Yes, default and static methods do not count towards the single abstract method rule.