Java OCA OCP Practice Question 2894

Question

Which of the following methods cannot be used to obtain a Path instance? (Choose all that apply.)

A.   new Path("data.txt")
B.   FileSystems.getDefault().getPath("data.txt")
C.   Paths.get(new URI("data.txt"))
D.   Paths.get("data","lynx.txt")
E.   new java.io.File("data.txt").toPath()
F.   new FileSystem().getPath("data")
G.   Paths.getPath("data.txt")


A, F.

Note

For this question, you need to rule out the answers that can be used to obtain a Path instance.

D and G both use the Paths.get() method, one with optional vararg values.

C uses an overloaded version of Paths.get() that takes a URI.

B is a longer form for getting a Path using a specific file system, in this case the default file system.

Finally, E uses a method added to java.io.File to make it easily compatible with Path.

The remaining choices A and F are the correct ones, because they call constructors on Path and FileSystem, respectively, instead of using the underlying factory methods.

The rest are invalid since they do not use the factory methods to gain access to instances.




PreviousNext

Related