Which of the following can be filled into the blank that would allow the method to compile?
public String getPathName(String fileName) { final Path p = ; return p.getFileName(); }
I. new File(fileName).toPath() II. new Path(fileName) III. FileSystems.getDefault().getPath(fileName)
D.
The Path method getFileName()
returns a Path instance, not a String.
The code does not compile, regardless of which line of code is inserted into the blank, making Option D the correct answer.
Statements I and III are two valid ways to create a Path instance.
If the method was updated to use Path as the return type, then Option B would be the correct answer.
Statement II would cause the method to not compile, because Path is an interface and requires a class to be instantiated.