LearnFrenzy
Sign in Take a free test

Control Flow Statements · Control Flow MCQ · Question 9

A null String in a classic switch Answer, explanation & discussion

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

What happens when the selector of a classic switch (s) on a String is null?

  • A default runs
  • B NullPointerException Correct
  • C The first case runs
  • D Nothing
Correct Answer: Option B

Java 21 switches can add case null to handle it.

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