1z0-819 Exam QuestionsBrowse all questions from this exam

1z0-819 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?

Show Answer
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

2 comments
Sign in to comment
d7bb0b2Option: C
Jan 10, 2024

C is correct, Supplier has a get method

OmnisumemOption: C
Apr 16, 2024

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()); }}