Exam 1z0-819 All QuestionsBrowse all questions from this exam
Question 31

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.)

    Correct Answer: B, C

    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.

Discussion
Mukes877Options: BC

B, C is correct others don't give required path

StavokOptions: BC

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

d7bb0b2Options: BC

B and C are correct

OmnisumemOptions: BC

Tetsted: BC.

TADIEWAOptions: BC

B,C are correct