Java Functional Interfaces MCQ Questions and Answers
Q. What is a functional interface in Java?
A. An interface with only one methodB. An interface that represents a function
C. An interface with abstract methods
D. An interface that can be used as a function
Q. Why are functional interfaces used in Java?
A. To enable lambda expressionsB. To simplify functional programming
C. To provide a way to create anonymous functions
All of the above
Q. Which package contains the functional interfaces in Java?
A. java.utilB. java.lang
C. java.functional
D. java.util.function
Q. How do you identify a functional interface in Java?
A. It must have exactly one abstract methodB. It must extend the FunctionalInterface interface
C. It must have the @FunctionalInterface annotation
All of the above
Q. What is the purpose of the @FunctionalInterface annotation?
A. To indicate that an interface is a functional interfaceB. To allow the interface to have multiple abstract methods
C. To enable lambda expressions for the interface
D. To provide additional functionality to the interface
Q. Can a functional interface have multiple abstract methods?
A. Yes, as long as they have default implementationsB. No, it must have exactly one abstract method
C. Yes, but only if they are overloaded methods
D. Yes, but they must have the same method signature
Q. Can a functional interface have default methods?
A. YesB. No
C. Only if they are private
D. Only if they are static
Q. Can a functional interface have static methods?
A. YesB. No
C. Only if they are private
D. Only if they are final
Q. What is the purpose of the Predicate functional interface in Java 8?
A. To produce resultsB. To consume values
C. To filter elements based on a condition
D. To transform values
Q. What is the purpose of the Function functional interface in Java 8?
A. To perform an operation on an input valueB. To transform one value into another
C. To filter elements based on a condition
D. To perform a side effect