Input Output(Java Program ) Questions and Answers

Question 1. Try{
File f = new File("a.txt");
}catch(Exception e){
}catch(IOException io){
}
Is this code create new file name a.txt ?
  1.    true
  2.    false
  3.    Compilation Error
  4.    None of these
Explanation:-
Answer: Option C. -> Compilation Error
IOException is unreachable to compiler because all exception are going to catch up by Exception block.

Question 2. System class is defined in .................
  1.    java.util package
  2.    java.lang package
  3.    java.io package
  4.    java.awt package
  5.    None of these
Explanation:-
Answer: Option B. -> java.lang package

Question 3. Which of these classes defined in java.io and used for file-handling are abstract?
A. InputStream
B. PrintStream
C. Reader
D. FileInputStream
E. FileWriter
  1.    Only A
  2.    Only C
  3.    A and C
  4.    B and D
  5.    A, B and E
Explanation:-
Answer: Option C. -> A and C

Question 4. When comparing java.io.BufferedWriter and java.io.FileWriter, which capability exist as a method in only one of two ?
  1.    closing the stream
  2.    flushing the stream
  3.    writting to the stream
  4.    writting a line separator to the stream
  5.    None of these
Explanation:-
Answer: Option D. -> writting a line separator to the stream
A newLine() method is provided in BufferedWriter which is not in FileWriter.