Java SE 8 Programmer II — Question 41
Given the code fragment:
Path path1 = Paths.get("/app/./sys/");
Path res1 = path1.resolve("log");
Path path2 = Paths.get("/server/exe/");
Path res1 = path1.resolve("/readme/");
System.out.println(res1);
System.out.println(res2);
What is the result?
Answer options
- A. /app/sys/log /readme/server/exe
- B. /app/log/sys /server/exe/readme
- C. /app/./sys/log /readme
- D. /app/./sys/log /server/exe/readme
Correct answer: C
Explanation
The variable 'res1' resolves to '/app/./sys/log' because it appends 'log' to the existing path. The second resolve call with '/readme/' results in '/readme' since it starts from the root. The other options either misrepresent the path structure or incorrectly resolve the paths.