Oracle
1Z0-851 · Question #114
Given: 11. class X { public void foo() { System.out.print("X "); } } 12. 13. public class SubB extends X { 14. public void foo() throws RuntimeException { 15. super.foo(); 16. if (true) throw new…
The correct answer is A. X, followed by an Exception. X Exception in thread "main" java.lang.RuntimeException at SubB.foo(SubB.java:5) at SubB.main(SubB.java:9)
Exceptions and Assertions
Question
Given: 11. class X { public void foo() { System.out.print("X "); } } 12. 13. public class SubB extends X { 14. public void foo() throws RuntimeException { 15. super.foo(); 16. if (true) throw new RuntimeException(); 17. System.out.print("B "); 18. } 19. public static void main(String[] args) { 20. new SubB().foo(); 21. } 22. } What is the result?
Options
- AX, followed by an Exception.
- BNo output, and an Exception is thrown.
- CCompilation fails due to an error on line 14.
- DCompilation fails due to an error on line 16.
- ECompilation fails due to an error on line 17.
- FX, followed by an Exception, followed by B.
How the community answered
(48 responses)- A73% (35)
- B4% (2)
- D2% (1)
- E15% (7)
- F6% (3)
Explanation
X Exception in thread "main" java.lang.RuntimeException at SubB.foo(SubB.java:5) at SubB.main(SubB.java:9)
Topics
#method overriding#RuntimeException#unchecked exceptions#execution flow
Community Discussion
No community discussion yet for this question.