nerdexam
Oracle

1Z0-851 · Question #180

Given: 05. class A { 06. void foo() throws Exception { throw new Exception(); } 07. } 08. class SubB2 extends A { 09. void foo() { System.out.println("B "); } 10. } 11. class Tester { 12. public…

The correct answer is D. Compilation fails due to an error on line 14. See the full explanation below for the reasoning.

Question

Given: 05. class A { 06. void foo() throws Exception { throw new Exception(); } 07. } 08. class SubB2 extends A { 09. void foo() { System.out.println("B "); } 10. } 11. class Tester { 12. public static void main(String[] args) { 13. A a = new SubB2(); 14. a.foo(); 15. } 16. } What is the result?

Options

  • AB
  • BB, followed by an Exception.
  • CCompilation fails due to an error on line 9.
  • DCompilation fails due to an error on line 14.
  • EAn Exception is thrown with no other output.

How the community answered

(64 responses)
  • A
    11% (7)
  • B
    2% (1)
  • C
    3% (2)
  • D
    80% (51)
  • E
    5% (3)

Community Discussion

No community discussion yet for this question.

Full 1Z0-851 Practice