Oracle
1Z0-809 · Question #10
Given the code fragment: public class FileThread implements Runnable { String fName; public FileThread (String fName) { this.fName = fName; } public void run () { System.out.println(fName); } public…
The correct answer is B. The program prints files names concurrently. You've hit your session limit · resets 5:20pm (America/New_York)
Question
Given the code fragment:
public class FileThread implements Runnable {
String fName;
public FileThread (String fName) { this.fName = fName; }
public void run () { System.out.println(fName); }
public static void main (String[] args) throws IOException,
InterruptedException {
ExecutorService executor = Executors.newCachedThreadPool();
Stream<Path> listOfFiles = Files.walk(Paths.get("Java Projects"));
listOfFiles.forEach(line -> {
executor.execute(new FileThread(line.getFileName().toString())); //
line n1
});
executor.shutdown();
executor.awaitTermination(5, TimeUnit.DAYS); //
line n2
}
}
The Java Projects directory exists and contains a list of files.
What is the result?
Options
- AThe program throws a runtime exception at line n2.
- BThe program prints files names concurrently.
- CThe program prints files names sequentially.
- DA compilation error occurs at line n1.
How the community answered
(25 responses)- A8% (2)
- B76% (19)
- C12% (3)
- D4% (1)
Explanation
You've hit your session limit · resets 5:20pm (America/New_York)
Community Discussion
No community discussion yet for this question.