Java OCA OCP Practice Question 2888

Question

What is the output of the following code?

Path path1 = Paths.get("/data/../java.txt"); 
Path path2 = Paths.get("./sql.txt"); 
System.out.println(path1.resolve(path2)); 
System.out.println(path2.resolve(path1)); 
A.   /data/../java.txt/./sql.txt /*from  w w w  . j  a  v a 2  s. c  o  m*/

     /data/../java.txt 

B.   /data/../java.txt/./sql.txt 

     ./sql.txt/data/../java.txt 

C.   /java.txt 

     /sql.txt 

D.   /javas.txt/sql.txt 

     /java.txt 

E.   It compiles but throws an exception at runtime. 


A.

Note

The code compiles and runs without issue, so E is incorrect.

For this question, you have to remember two things.

First, the resolve() method does not normalize any path symbols, so C and D are not correct.

Second, calling resolve() with an absolute path as a parameter returns the absolute path, so A is correct and B is incorrect.




PreviousNext

Related