Java OCA OCP Practice Question 3207

Question

Given the following code:

import java.io.*;
public class Main {

  public static void main(String[] args)
  throws IOException, ClassNotFoundException {
    String[] dirNames = {//ww w  . ja v  a  2  s . c om
        "." + File.separator + "dir1",
        "." + File.separator + "dir2",
        "." + File.separator + "dir1" + File.separator + "dir2"
    };
    for(String dir : dirNames) {
      File file = new File(dir, "myFile.txt");
      System.out.print(/* INSERT EXPRESSION HERE */);  // (1)
    }
  }
 }

Assume that each directory named in the array dirNames has a file named "myFile.txt".

Which expressions, when inserted at (1), will result in the output truetruetrue?

Select the three correct answers.

  • (a) file.found()
  • (b) file.isFile()
  • (c) !file.isDirectory()
  • (d) file.exists()
  • (e) file.isAFile()
  • (f) !file.isADirectory()


(b), (c), (d)

Note

The class File does not have methods called found, isAFile(), or isADirectory().




PreviousNext

Related