Java SE 8 Programmer II — Question 98

Given the code fragment:
Path path1 = Paths.get("/app/./sys/");
Path res1 = path1.resolve("log");
Path path2 = Paths.get("/server/exe/");
Path res1 = path2.resolve("/readme/");
System.out.println(res1);
System.out.println(res2);
What is the result?

Answer options

Correct answer: D

Explanation

The correct answer is D because the method resolve() appends the specified path to the existing path. In this case, /readme/ is resolved relative to /server/exe/, while /app/./sys/ resolves to /app/sys/ and appends log, resulting in /app/./sys/log. The other options do not represent the correct paths generated by the resolve() method.