Return to site

JAVA CERTIFICATION QUESTION: Functional interfaces and lambdas expressions

· java,ocp

Given:

 

What is the given program's output?

A. 1

B. 2

C. 3

D. Compilation fails on line 1

E. Compilation fails on line 2

 

 

Answer👇👇👇

·ꓭ uoᴉʇdo sᴉ ɹǝʍsuɐ ʇɔǝɹɹoɔ ǝɥꓕ

The Calculable interface has only one abstract method, hence it's a functional interface.

The lambda expression used on line 1 represents that abstract method - it has nothing to do with the default method in the same interface.

That lambda expression doubles its argument.

Therefore, when number 1 is passed to the change method on line 2, number 2 is returned and printed out.