Given the code fragment:
Supplier supplier = () -> "Hello World":
// line 1
Which statement on line 1 is calling the method of the supplier object correctly?
Given the code fragment:
Supplier supplier = () -> "Hello World":
// line 1
Which statement on line 1 is calling the method of the supplier object correctly?
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.
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()); }}
C is correct, Supplier has a get method