LearnFrenzy
Sign in Take a free test

Object Class and Wrapper Classes · Object and Wrapper Classes MCQ · Question 13

Unboxing a null wrapper Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 13 Back to Exercise

What happens at int n = map.get("missing"); when the key is absent (map is a Map<String, Integer>)?

  • A n becomes 0
  • B NullPointerException – get returns null, which cannot be unboxed Correct
  • C Compile error
  • D n becomes -1
Correct Answer: Option B

Use getOrDefault("missing", 0).

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links