What is the result?

Given:

What is the result?

Given:

What is the result?

A.
5

B.
6

C.
An exception is thrown at runtime

D.
Compilation fails due to an error on line 6

E.
Compilation fails due to an error on line 7

Explanation:

The code compile fine but java.lang.NullPointerException is thrown at runtime.
x has no value. The code would run if line 2 was changed to:
Integer x = 3;



Leave a Reply 1

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