1Z0-809 practice question 16 of 25

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?

Full set: 196 questions
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:
N
Explanation

The provided code fragment has two fatal compilation errors. First, the variable res1 is declared and initialized twice within the same scope, which is illegal in Java (Path res1 = ...;). Second, the final line System.out.println(res2); attempts to print a variable res2 that has not been declared. Due to these errors, the code will not compile, and therefore none of the options representing program output can be correct. An exam question should have a correct option, indicating this question is flawed as written.

Why Incorrect

A. The code does not compile, so it cannot produce this or any other runtime output.
B. The code fails to compile and thus cannot execute to produce this output.
C. This output is not possible because

References

1. JLS (SE 8) §14.4.2, “Local Variable Declarations” – a variable may not be declared twice in the same scope.

2. JLS (SE 8) §16, “Definite Assignment”, compile-time rules on undeclared identifiers.

Scroll to Top