Java OCA OCP Practice Question 2878

Question

What is the result of executing the following code? (Choose all that apply.)

1: Path path = Paths.get("data.txt"); 
2:         BasicFileAttributes attributes = Files.readAttributes(path, BasicFileAttributes.class); 
3: if(attributes.size()>0 && attributes.creationTime().toMillis()>0) { 
4:    attributes.setTimes(null,null,null); 
5: } 
  • A. It compiles and runs without issue.
  • B. The code will not compile because of line 2.
  • C. The code will not compile because of line 3.
  • D. The code will not compile because of line 4.
  • E. The code compiles but throws an exception at runtime.


D.

Note

The setTimes() method is available only on BasicFileAttributeView, not the read only BasicFileAttributes class, so line 4 will not compile and D is correct.

You need to retrieve an instance of the view class to update the data.

The rest of the lines compile without issue and only D is correct.




PreviousNext

Related