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)- A11% (7)
- B2% (1)
- C3% (2)
- D80% (51)
- E5% (3)
Community Discussion
No community discussion yet for this question.