Return to site

JAVA CERTIFICATION QUESTION: Built-in Functional interfaces

· java,ocp


What is the output of the given code fragment?

  • A. java
  • B. Java
  • C. JAVA
  • D. Compilation fails on line 1
  • E. Compilation fails on line 2
  • F. Compilation fails on line 3

#java #certificationquestion #ocp

The lambda expression and method reference on lines 1 and 2 use methods defined in the String class.

Both of the assignments are valid.

When composing functions, the first type parameter (the type of the input) of the target function

must match the second type parameter (the type of the result) of the argument function.

In the given code, the input type of function f1 is String, while the result type of function f2 is Object.

This type of mismatch leads to a compile-time error.

Had the result type of function f2 been String, option A would have been the correct answer.

·ꓞ sᴉ ɹǝʍsuɐ ʇɔǝɹɹoɔ ǝɥʇ uoᴉsnʅɔuoꓛ