Java Reference
In-Depth Information
17. Which of the following exceptions are thrown by the JVM? (Select three.)
A. java.io.IOException
B. NullPointerException
C. ExceptionInInitializerError
D. NumberFormatException
E. ArrayIndexOutOfBoundsException
18. Given the following class definition:
1. import java.io.*;
2.
3. public class MyFileReader2 {
4. public void readFromFile(String fileName) throws IOException {
5. FileReader fis = new FileReader(fileName);
6. System.out.println(fileName + “ was found”);
7. char data = (char) fis.read();
8. System.out.println(“Just read: “ + data);
9. System.out.println(“End of readFromFile”);
10. }
11.
12. public static void main(String [] args) {
13. MyFileReader2 reader = new MyFileReader2();
14. reader.readFromFile(“greeting.txt”);
15. System.out.println(“End of main”);
16. }
17. }
and given that the fi le greeting.txt has one line of text:
Welcome
which one of the following statements is true?
A. The code compiles and the output is “W”.
B. Line 4 generates a compiler error.
C. Line 5 generates a compiler error.
D. Line 7 generates a compiler error.
E. Line 14 generates a compiler error.
19. Given the following class definition:
1. public class DoSomething {
2. public void go() {
3. System.out.print(“A”);
Search WWH ::




Custom Search