Java OCA OCP Practice Question 2048

Question

Given the following program:.

import java.io.EOFException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
  public static void main(String[] args) {
    try {//from  w ww .j  a va 2s  . c  om
      FileInputStream fis = new FileInputStream("seq.txt");
      InputStreamReader isr = new InputStreamReader(fis);
      int i = isr.read();
      while (i != -1) {
        System.out.print((char)i + "|");
        i = isr.read();
      }
    } catch (FileNotFoundException fnf) {
      System.out.println("File not found");
    } catch (EOFException eofe) {
      System.out.println("End of stream");
    } catch (IOException ioe) {
      System.out.println("Input error");
    }
  }
}

Assume that the file "seq.txt" exists in the current directory, has the required access permissions, and contains the string "Hello".

Which statement about the program is true?.

Select the one correct answer.

  • (a) The program will not compile because a certain unchecked exception is not caught.
  • (b) The program will compile and print H|e|l|l|o|Input error.
  • (c) The program will compile and print H|e|l|l|o|End of stream.
  • (d) The program will compile, print H|e|l|l|o|, and then terminate normally.
  • (e) The program will compile, print H|e|l|l|o|, and then block in order to read from the file.
  • (f) The program will compile, print H|e|l|l|o|, and terminate because of an uncaught exception.


(d)

Note

The read() method of an InputStreamReader returns -1 when the end of the stream is reached.




PreviousNext

Related