nerdexam
Oracle

1Z0-851 · Question #184

Given: public class Boxer1{ Integer i; int x; public Boxer1(int y) { x = i+y; System.out.println(x); } public static void main(String[] args) { new Boxer1(new Integer(4)); } } What is the result?

The correct answer is D. A NullPointerException occurs at runtime. See the full explanation below for the reasoning.

Question

Given: public class Boxer1{ Integer i; int x; public Boxer1(int y) { x = i+y; System.out.println(x); } public static void main(String[] args) { new Boxer1(new Integer(4)); } } 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

(14 responses)
  • A
    14% (2)
  • B
    7% (1)
  • D
    79% (11)

Community Discussion

No community discussion yet for this question.

Full 1Z0-851 Practice