What is the result?

View the Exhibit:

Given the following code fragment:
<code>
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();
}
</code>
What is the result?

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)) {
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.



Leave a Reply 1

Your email address will not be published. Required fields are marked *