Java OCA OCP Practice Question 2525

Question

Code in which of the following options can be inserted at //INSERT CODE HERE?.

public class Main {
    public static void main(String args[]) {
        ExecutorService service = Executors.newFixedThreadPool(5);
        service.submit(new Task());
    }
}
//INSERT CODE HERE
a  class Task implements Executor {public void execute() {} }
b  class Task implements Executable {public void execute() {} }
c  class Task implements Submittable {public void submit() {} }
d  class Task implements Callable<Void> {public Void call() {return null;} }
e  class Task implements Callable<Integer>  {public  Integer  call() {return 1;} }
f  class Task implements Callable {public void call() {} }


d, e

Note

You can pass either Runnable or Callable to method submit() of ExecutorService.

Options (d) and (e) correctly implement the Callable<T> interface.

Callable's method call() returns a value.

If you don't want it to return a value, implement Callable<Void>, define the return type of call() to Void, and return null from it.




PreviousNext

Related