Java OCA OCP Practice Question 2052

Question

Given the following program:.

import java.io.BufferedReader;
import java.io.EOFException;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class Main {
 public static void main(String[] args) {
   try {// w  ww  .  ja  v  a2  s . co m
     FileReader fr = new FileReader("greetings.txt");
     BufferedReader br = new BufferedReader(fr);
     System.out.print(br.readLine() + "|");
     System.out.print(br.readLine() + "|");
     System.out.print(br.readLine() + "|");
   } catch (EOFException eofe) {
     System.out.println("End of stream");
   } catch (IOException ioe) {
     System.out.println("Input error");
   }
 }
}

Assume that the file "greeting.txt" exists in the current directory, has the required access permissions, and contains the following two lines of text:.

Hello
Howdy

Which statement is true about the program?.

Select the one correct answer.

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


(b)

Note

The readLine() method of a BufferedReader returns null when the end of the stream is reached.




PreviousNext

Related