Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 215

Given the code fragment:

public void recDelete (String dirName) throws IOException {

File [ ] listOfFiles = new File (dirName) .listFiles();

if (listOfFiles ! = null && listOfFiles.length >0) {

for (File aFile : listOfFiles) {

if (aFile.isDirectory ()) {

recDelete (aFile.getAbsolutePath ());

} else {

if (aFile.getName ().endsWith (".class"))

aFile.delete ();

}

}

}

}

Projects contains subdirectories that contain .class files and is passed as an argument to the recDelete () method when it is invoked.

Assume that -

What is the result?

.class files in the Projects directory and its subdirectories.

    Correct Answer: A

    The method recursively deletes all the .class files in the specified directory and its subdirectories. The code checks if each file in the directory is a directory itself, in which case it calls the recDelete method again on that directory. If the file is not a directory, it checks if the file ends with .class and deletes it if it does. Hence, the method deletes all the .class files in the Projects directory and its subdirectories.

Discussion
maslacOption: A

Answer is: The method deletes all the .class files in the Projects directory and its subdirectories.

WilsonKKerll

I agree.

Ritesh_Option: A

answer is A

steefaandOption: A

Nothing is correct. Method deletes all .class files in Project directory and its subdirectories.

WilsonKKerllOption: A

Answer is A.