LearnFrenzy
Sign in Take a free test

Classes and Objects · Classes and Objects MCQ · Question 6

What causes NullPointerException? Answer, explanation & discussion

  • MCQ
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 6 Back to Exercise

Which line throws NullPointerException if s is null?

  • A if (s == null)
  • B s.length() Correct
  • C String t = s;
  • D System.out.println(s);
Correct Answer: Option B

Comparing, assigning or printing null is fine; dereferencing it is not.

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