Oracle
1Z0-851 · Question #267
Given: class X { public void foo() { System.out.print("X "); } } public class SubB extends X { public void foo() throws RuntimeException { super.foo(); if (true) throw new RuntimeException()…
The correct answer is A. X, followed by an Exception. See the full explanation below for the reasoning.
Question
Given: class X { public void foo() { System.out.print("X "); } } public class SubB extends X { public void foo() throws RuntimeException { super.foo(); if (true) throw new RuntimeException(); System.out.print("B "); } public static void main(String[] args) { new SubB().foo(); } } 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
(39 responses)- A77% (30)
- B3% (1)
- C8% (3)
- D3% (1)
- E10% (4)
Community Discussion
No community discussion yet for this question.