Java OCA OCP Practice Question 2267

Question

Consider the following program:

import java.nio.file.*;
import java.io.IOException;

public class Main {
   public static void main(String []args) throws IOException {
      Path aFilePath = Paths.get("D:\\directory\\file.txt");
      System.out.println(aFilePath.isAbsolute());
   }
}

Assuming that the file D:\\directory\\file.txt does not exist, what will be the behavior of this program?.

  • A. this program prints false.
  • B. this program prints true.
  • C. this program crashes by throwing a java.io.IOException.
  • D. this program crashes by throwing a java.nio.file.NoSuchFileException.


B.

Note

to use methods such as isAbsolute(), the actual file need not exist.

Because the path represents an absolute path (and not a relative path), this program prints true.




PreviousNext

Related