Java OCA OCP Practice Question 2200

Question

What is the output of the following code snippet?

Assume the two directories referenced both exist and are symbolic links to the same location within the file system.

if(Files.isSameFile("/p1/p2", "/p3/p4")) 
   System.out.println("Same!"); 
else 
   System.out.println("Different!"); 
  • A. Same!
  • B. Different!
  • C. The code does not compile.
  • D. The code compiles but throws an exception at runtime.
  • E. None of the above


C.

Note

The code does not compile because Files.isSameFile() requires Path instances, not String values.

Option C is the correct answer.

If Path values had been used, then the code would compile and print Same!, and Option A would be the correct answer since the isSameFile() method does follow symbolic links.




PreviousNext

Related