Java SE 17 Developer — Question 54
Given:
Path p1 = Path.of("/home");
Path p2 = Path.of("../data");
System.out.println(p1.resolve(p2));
System.out.println(p2.resolve(p1));
What is the result?
Answer options
- A. /home/data /data/home
- B. /home/data ../data
- C. /home/../data /home
- D. /home/../data ../data/home
- E. /home/data /data
Correct answer: C
Explanation
The correct answer is C because resolving p2 against p1 leads to the path '/home/../data', while resolving p1 against p2 results in the absolute path '/home'. The other options do not accurately represent the results of the resolve method for these Path instances.