SCJP Module-10 Question-6


 

SCJP Module-10 Question-6

The Sample code given below will test your understanding of writing file using FileWriter class in Java.

The Sample code given below will test your understanding of writing file using FileWriter class in Java.

Given a sample code:

1    import java.io.*;

2    class Test3 {
3    public static void main(String[] args) {
4    try {
5    File w = new File("user1.txt");
6    FileWriter fw = new FileWriter(w);
7    fw.write("helllo user");
8    fw.close();
9    } catch (IOException e) {
10  System.out.println(e);
}}

What will the result if it is compiled and run ?

(A) Makes a file
(B) Error caught at line no 6.  
(C) Compile time error.
(D) Raise run-time exception.

Answer:

(B)

Ads