Java OCA OCP Practice Question 2575

Question

Consider the following code segment:

try (BufferedReader inputFile
    = new BufferedReader(new FileReader(srcFile));
    BufferedWriter outputFile/*from w ww  .j av  a  2s  .c om*/
    = new BufferedWriter(new FileWriter(dstFile))) {  // TRY-BLOCK
    int ch = 0;
    while( (ch = inputFile.read()) != -1) {
        outputFile.write( (char)ch );
    }
} catch (FileNotFoundException
    | IOException exception) {                 // MULTI-CATCH-BLOCK
    System.err.println("Error in opening or processing file "
        + exception.getMessage());
}

Assume that srcFile and dstFile are Strings.

Which one of the following options correctly describes the behavior of this program?.

  • a)This program will get into an infinite loop because the condition check for end-of-stream (checking != -1) is incorrect.
  • b)This program will get into an infinite loop because the variable ch is declared as int instead of char.
  • c)This program will result in a compiler error in line marked with comment TRY-BLOCK because you need to use , (comma) instead of ; (semi-colon) as separator for opening multiple resources.
  • d)This program will result in a compiler error in line marked with comment MULTI-CATCH-BLOCK because IOException is the base class for FileNotFoundException.


d)



PreviousNext

Related