Skip to content
Sharp

Java Threading · interview question

What will be the output of the following code snippet if executed successfully?

Multiple choiceEasychapter-15-curatedpremiumjava-threadingexecutorservice
java
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.submit(() -> System.out.println("Task completed"));
executor.shutdown();
Choose one answer
Answer and explanation

Correct answer

D. Task completed

Why

The code snippet submits a task to an ExecutorService, and assuming there are no logical errors or exceptions, it will print 'Task completed'.

Test yourself on Java Threading

A free test with instant, explained results. No account needed.

Start free test
All Java Threading questions →