Given:
1. import java.io.IOException;
2.
3. class A {
4.
5. public void process() {
6. System.out.print(“A,”);
7. }
8.
9. }
10.
11.
12. class B extends A {
13.
14. public void process() throws IOException {
15. super.process();
16. System.out.print(“B,”);
17. throw new IOException();
18. }
19.
20. public static void main(String[] args) {
21. try {
22. new B().process();
23. } catch (IOException e) {
24. System.out.println(“Exception”);
25. }
26. }
27. }
What is the result?
A.
Exception
B.
A,B,Exception
C.
Compilation fails because of an error in line 20.
D.
Compilation fails because of an error in line 14.
E.
A NullPointerException is thrown at runtime.
Explanation:
Main.java:14: process() in B cannot override process() in A; overridden method does not throw java.io.IOException
public void process() throws IOException {
^
1 error
D