nerdexam
Oracle

1Z0-851 · Question #18

Given that the current directory is empty, and that the user has read and write permissions, and the following: import java.io.*; public class DOS { public static void main(String[] args) { File dir…

The correct answer is E. The file system has a directory named newDir, containing a file f1.txt. See the full explanation below for the reasoning.

Question

Given that the current directory is empty, and that the user has read and write permissions, and the following: import java.io.*; public class DOS { public static void main(String[] args) { File dir = new File("dir"); dir.mkdir(); File f1 = new File(dir, "f1.txt"); try { f1.createNewFile(); } catch (IOException e) { ; } File newDir = new File("newDir"); dir.renameTo(newDir); } } Which statement is true?

Options

  • ACompilation fails.
  • BThe file system has a new empty directory named dir.
  • CThe file system has a new empty directory named newDir.
  • DThe file system has a directory named dir, containing a file f1.txt.
  • EThe file system has a directory named newDir, containing a file f1.txt.

How the community answered

(24 responses)
  • A
    4% (1)
  • B
    13% (3)
  • C
    4% (1)
  • E
    79% (19)

Community Discussion

No community discussion yet for this question.

Full 1Z0-851 Practice