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)) {
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?
A.
Compilation fails
B.
6
C.
4
D.
1
E.
3
Explanation:
The program will compile and run.
Referring to the exhibit there will be six nodes that matches glob:*java.
C