Java OCA OCP Practice Question 1926

Question

Which interface name inserted into the blank below allows the code snippet to compile?

Path file = Paths.get("/data/movie.txt"); 
BasicFileAttributes b = Files.readAttributes(file, ___); 
  • A. BasicFileAttributes.class
  • B. DosFileAttributes.class
  • C. PosixFileAttributes.class
  • D. All of the above


D.

Note

DosFileAttributes and PosixFileAttributes extend BasicFileAttributes.

They are compatible with the readAttributes() method signature.

They produce instances that inherit the interface BasicFileAttributes.

Yhey can be assigned to a variable b of type BasicFileAttributes without an explicit cast.

All three interfaces are permitted, and Option D is the correct answer.




PreviousNext

Related