Exam 1z0-819 All QuestionsBrowse all questions from this exam
Question 190

Given the code fragment:

Supplier supplier = () -> "Hello World":

// line 1

Which statement on line 1 is calling the method of the supplier object correctly?

    Correct Answer: C

    In Java, the Supplier functional interface is used to represent a supplier of results. It has a single abstract method called 'get()' which is used to retrieve or supply the result. Therefore, the correct way to call the method of the supplier object correctly on line 1 is to use 'supplier.get()'. The other options, 'apply()', 'accept()', and 'test()', do not belong to the Supplier interface.

Discussion
OmnisumemOption: C

tested. to check for yourself: import java.util.function.Supplier; public class q190 { public static void main (String[] args) { Supplier supplier = () -> "Hello World"; //System.out.println(supplier.apply()); //System.out.println(supplier.accept()); System.out.println(supplier.get()); //System.out.println(supplier.test()); }}

d7bb0b2Option: C

C is correct, Supplier has a get method