nerdexam
Oracle

1Z0-805 · Question #7

View the Exhibit: Given the following code fragment: class Finder extends SimpleFileVisitor<Path> { private final PathMatcher matcher; private static int numMatches = 0; Finder() { matcher =…

The correct answer is B. 6. The program will compile and run. Referring to the exhibit there will be six nodes that matches glob:*java.

Java I/O Fundamentals

Question

View the Exhibit:

Given the following code fragment:

class Finder extends SimpleFileVisitor<Path> { private final PathMatcher matcher; private static int numMatches = 0; Finder() { matcher = FileSystems.getDefault().getPathMatcher("glob:*java"); } void find(Path file) { Path Name = file.getFileName(); if (name != null && matcher.matches(name)) { Oracle 1Z0-805 Exam numMatches++; } } void report() { System.out.println("Matched: " + numMatches); } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { find(file); return CONTINUE; } } public class Visitor { public static void main(String[] args) throws IOException { Finder finder = new Finder(); Files.walkFileTree(Paths.get("d:\Project"), finder); finder.report(); } } What is the result?

Exhibits

1Z0-805 question #7 exhibit 1
1Z0-805 question #7 exhibit 2

Options

  • ACompilation fails
  • B6
  • C4
  • D1
  • E3

How the community answered

(44 responses)
  • A
    9% (4)
  • B
    73% (32)
  • C
    2% (1)
  • D
    5% (2)
  • E
    11% (5)

Explanation

The program will compile and run. Referring to the exhibit there will be six nodes that matches glob:*java.

Topics

#SimpleFileVisitor#PathMatcher#glob pattern#NIO.2 file traversal

Community Discussion

No community discussion yet for this question.

Full 1Z0-805 Practice