What is the result?

Given:

11. static class A {
12. void process() throws Exception { throw new Exception(); }
13. }
14. static class B extends A {
15. void process() { System.out.println(“B”); }
16. }
17. public static void main(String[] args) {
18. new B().process();
19. }

What is the result?

Given:

11. static class A {
12. void process() throws Exception { throw new Exception(); }
13. }
14. static class B extends A {
15. void process() { System.out.println(“B”); }
16. }
17. public static void main(String[] args) {
18. new B().process();
19. }

What is the result?

A.
B

B.
The code runs with no output.

C.
Compilation fails because of an error in line 12.

D.
Compilation fails because of an error in line 15.

E.
Compilation fails because of an error in line 18.



Leave a Reply 1

Your email address will not be published. Required fields are marked *


Matti

Matti

A is correct. This question is about static inner class.
Line 18 is ok, because B is static inner class (with a regular inner class, have to assign:
new OuterClassName. new B().process())
line 15 is ok, this overriding is ok.