Given:
Path p1 = Paths.get(“/scratch/exam/topsecret/answers”);
Path p2 = Paths.get(“/scratch/exam/answers/temp.txt”);
Path p3 = Paths.get(“/scratch/answers/topsecret”);
Which two statements print ..\..\..\answers\topsecret? (Choose two.)
Given:
Path p1 = Paths.get(“/scratch/exam/topsecret/answers”);
Path p2 = Paths.get(“/scratch/exam/answers/temp.txt”);
Path p3 = Paths.get(“/scratch/answers/topsecret”);
Which two statements print ..\..\..\answers\topsecret? (Choose two.)
To determine the relative paths, we need to use the relativize method correctly. The method computes the relative path from the first path to the second path. For p2.relativize(p3), the starting path is /scratch/exam/answers/temp.txt, and the ending path is /scratch/answers/topsecret, resulting in ..\..\..\answers\topsecret. For p1.relativize(p3), the starting path is /scratch/exam/topsecret/answers, and the ending path is /scratch/answers/topsecret, resulting in ..\..\..\answers\topsecret. Hence, both these calls produce the correct relative path.
B, C is correct others don't give required path
The two statements that print ..\..\..\answers\topsecret are options B and C. In option B, p2.relativize(p3) constructs a relative path from p2 to p3. Since p2 represents the path /scratch/exam/answers/temp.txt, and p3 represents the path /scratch/answers/topsecret, the relative path from p2 to p3 is ..\..\..\answers\topsecret. In option C, p1.relativize(p3) constructs a relative path from p1 to p3. Since p1 represents the path /scratch/exam/topsecret/answers, and p3 represents the path /scratch/answers/topsecret, the relative path from p1 to p3 is also ..\..\..\answers\topsecret
B and C are correct
Tetsted: BC.
B,C are correct