Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 206

Given the code fragment:

Path path1 = Paths.get("/app/./sys/");

Path res1 = path1.resolve("log");

Path path2 = Paths.get("/server/exe/");

Path res2 = path2.resolve("/readme/");

System.out.println(res1);

System.out.println(res2);

What is the result?

    Correct Answer: C

    Given the code fragment, `Path path1 = Paths.get("/app/./sys/");` and `Path res1 = path1.resolve("log");` results in /app/./sys/log. This is because resolve adds the 'log' segment to the existing path without normalizing the path (i.e., it does not remove the './'). Next, `Path path2 = Paths.get("/server/exe/");` and `Path res2 = path2.resolve("/readme/");` results in /readme. When resolving an absolute path, the result is the absolute path itself, so the parent path is ignored. Therefore, the output will be /app/./sys/log /readme.

Discussion
jduarteOption: C

Answer C. Tested

steefaandOption: C

C is correct.

iSnoverOption: C

The answer is C, it prints "/app/./sys/log /readme"

WilsonKKerllOption: C

Answer is C.