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 questionsThe 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.
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
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.
Keep practicing
Take the free 1Z0-809 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other 1Z0-809 practice questions
- Question 2Given: class Student { String course, name, city; public Student (String name, String cou…
- Question 3Given: class Worker extends Thread { CyclicBarrier cb; public Worker(CyclicBarrier cb) { …
- Question 4Given the code fragment: Path file = Paths.get (“courses.txt”); // line n1 Assume the cou…
- Question 5Given that /green.txt and /colors/yellow.txt are accessible, and the code fragment: Path …
- Question 6Given the code fragment:List<String> empDetails = Arrays.asList(“100, Robin, HR”,“200, Ma…
- Question 7Given the code fragment: List str = Arrays.asList (“my”, “pen”, “is”, “your’, “pen”); Pre…
