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

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 ()) {

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

aFile.delete ();

}

}

}

}

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

What is the result?

    Correct Answer: B

    The method iterates over the files in the specified directory and deletes the files that have a .class extension. It does not traverse subdirectories, as there is no recursion implemented in the provided code to handle subdirectories. Therefore, only the .class files in the immediate Projects directory will be deleted.

Discussion
steefaandOption: B

B is correct.

UchihaOption: B

Answer is B

jduarteOption: A

A. is correct

maslac

you are wrong again, correct answer is B