Which two expressions create a valid Java Path instance? (Choose two.)
Which two expressions create a valid Java Path instance? (Choose two.)
To create a valid Java Path instance, the Paths.get method is commonly used. The statement Paths.get("foo") is valid. Additionally, Path can be created using a URI, but the correct method is Path.of(URI), which is similar to the Paths.get method. As such, Paths.get(new URI("file:///domains/oracle/test.txt")) would be valid if changed to Paths.get(URI.create("file:///domains/oracle/test.txt"). However, the provided incorrect option Paths.get(new URI()) is assumed to be an error in transcription. 'Paths.get(URL.create("file:///domains/oracle/test.txt"))' is incorrect because URL does not have a create method. 'Paths.getPath("too")' and 'new Path("foo")' are also incorrect since Paths does not have a method named getPath, and Path is an interface that cannot be instantiated.
E correct if URL changes to URI (URL doesn't have create method) A correct B failed Paths doesn't have method getPath() C failed Path doesn't have get(). It has of(). D failed Path - interface
A = ok E = ok (paths.get accepts string and URI as argument)
tested: AE. We suppose it is URI.create instead of URL.create...
A and E
You can easily create a Path object by using one of the following get methods from the Paths (note the plural) helper class: Path p1 = Paths.get("/tmp/foo"); Path p2 = Paths.get(args[0]); Path p3 = Paths.get(URI.create("file:///Users/joe/FileTest.java"));
A and E are correct