Oracle
1Z0-851 · Question #109
Given: 01. public class Boxer1{ 02. Integer i; 03. int x; 04. public Boxer1(int y) { 05. x = i+y; 06. System.out.println(x); 07. } 08. public static void main(String[] args) { 09. new Boxer1(new…
The correct answer is D. A NullPointerException occurs at runtime. See the full explanation below for the reasoning.
Question
Given: 01. public class Boxer1{ 02. Integer i; 03. int x; 04. public Boxer1(int y) { 05. x = i+y; 06. System.out.println(x); 07. } 08. public static void main(String[] args) { 09. new Boxer1(new Integer(4)); 10. } 11. } What is the result?
Options
- AThe value "4" is printed at the command line.
- BCompilation fails because of an error in line 5.
- CCompilation fails because of an error in line 9.
- DA NullPointerException occurs at runtime.
- EA NumberFormatException occurs at runtime.
- FAn IllegalStateException occurs at runtime.
How the community answered
(47 responses)- A9% (4)
- B2% (1)
- C2% (1)
- D81% (38)
- E6% (3)
Community Discussion
No community discussion yet for this question.