What is the result?

Given the 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?

Given the 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

F.
Not possible to answer due to missing exhibit.

Explanation:
Note: TheFileSystems.getDefault() returns the default FileSystem. The default file system creates objects that provide access to the file systems accessible to the Java virtual machine. The working directory of the file system is the current user directory, named by the system property user.dir.



Leave a Reply 2

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


GoodLuck

GoodLuck

F due to lack of information on the D:\\Project?