Java OCA OCP Practice Question 2931

Question

Given:

3. import java.io.*;  
4. public class Main {  
5.   public static void main(String[] args) throws Exception {  
6.     File file = new File("bigData.txt");  
7.     FileWriter w = new FileWriter(file);  
8.     w.println("lots o' data");  
9.     w.flush();  
10.     w.close();  
11. } } 

What is the result? (Choose all that apply.)

A.   An empty file named  "bigData.txt" is created.
B.   Compilation fails due only to an error on line 5.
C.   Compilation fails due only to an error on line 6.
D.   Compilation fails due only to an error on line 7.
E.   Compilation fails due only to an error on line 8.
F.   Compilation fails due to errors on multiple lines.
G.   A file named  "bigData.txt" is created, containing one line of data.


E is correct.

Note

It's legal for main() to declare an exception and not handle it.

Line 8 fails because the println() method is one of the easier-to-use methods included in the PrintWriter class but not in the more low-level FileWriter class.




PreviousNext

Related