Java SE 11 Developer (1Z0-819) — Question 199
Given the code fragment:
Supplier supplier = () -> "Hello World":
// line 1
Which statement on line 1 is calling the method of the supplier object correctly?
Answer options
- A. System.out.println(supplier.apply())
- B. System.out.println(supplier.accept());
- C. System.out.println(supplier.get());
- D. System.out.println(supplier.test());
Correct answer: C
Explanation
The correct answer is C because the Supplier interface defines a method called get() that returns a value. The other options are incorrect as apply(), accept(), and test() are methods from different functional interfaces (Function, Consumer, and Predicate respectively) and do not apply to the Supplier interface.