nerdexam
Oracle

1Z0-851 · Question #42

Given: import java.io.IOException; class A { public void process() { System.out.print("A,"); } } 13. class B extends A { 14. public void process() throws IOException { 15. super.process(); 16…

The correct answer is D. Compilation fails because of an error in line 14. Exception IOException is not compatible with throws clause in A.process()

Analyzing and Troubleshooting System Problems

Question

Given: import java.io.IOException; class A { public void process() { System.out.print("A,"); } } 13. class B extends A { 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?

Options

  • AException
  • BA,B,Exception
  • CCompilation fails because of an error in line 20.
  • DCompilation fails because of an error in line 14.
  • EA NullPointerException is thrown at runtime.

How the community answered

(51 responses)
  • A
    4% (2)
  • B
    2% (1)
  • C
    12% (6)
  • D
    80% (41)
  • E
    2% (1)

Explanation

Exception IOException is not compatible with throws clause in A.process()

Topics

#Java method overriding#checked exceptions#throws clause#compilation error

Community Discussion

No community discussion yet for this question.

Full 1Z0-851 Practice