<%@ include file="../../ga4.jsp" %> Files, File Dialogs [Java] - Quiz Explanation

Files and File Dialogs - Quiz Explanation

The answers you selected are indicated below, along with text that explains the correct answers.
 
1. When does the getParent() method in the File class return null?
Please select the best answer.
  A. When the file is a directory
  B. When the file has no parent
  C. When the file is a shortcut, symbolic link, or alias
  D. Never. If there's a problem, getParent() throws an IOException
  E. When the getParent() method is overloaded.
  The correct answer is B. If the File object points to a top-level directory (/ on Unix), then the file has no parent and null is returned.

2. To implement the FilenameFilter interface you must provide an implementation for which of the following methods?
Please select the best answer.
  A. filter()
  B. show()
  C. display()
  D. open()
  E. accept()
  The correct answer is E. The FilenameFilter interface defines the method public boolean accept(File dir, String name)

3. Java provides a means of accomplishing all of the actions listed below except one. Which action cannot be accomplished by using Java?
Please select the best answer.
  A. Create a new file
  B. Append data to an existing file
  C. Create a new directory
  D. Create a shortcut to a file
  E. Move a file to its parent directory
  The correct answer is D. New files can be created by opening a FileOutputStream to the file. Data can be appended to files with both FileOutputStreams and RandomAccessFile. Directories can be created with mkdir() or mkdirs(). Files can be moved to their parent directory using a combination of getParent() and renameTo(). The correct answer is D. New files can be created by opening a FileOutputStream to the file. Data can be appended to files with both FileOutputStreams and RandomAccessFile. Directories can be created with mkdir() or mkdirs(). Files can be moved to their parent directory using a combination of getParent() and renameTo(). The only one of these you can not do in pure Java is make a shortcut (or alias, or symbolic link) to a file.