LearnFrenzy
Sign in Take a free test

Control Flow Statements · Control Flow MCQ · Question 20

Order of cases in a pattern switch Answer, explanation & discussion

  • MCQ
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 20 Back to Exercise

Why must case Integer i when i > 0 come before case Integer i?

  • A Alphabetical order
  • B The unguarded case would match every Integer first, so a later more specific case would be unreachable (a compile error) Correct
  • C Guards run last
  • D It does not matter
Correct Answer: Option B

javac reports "this case label is dominated by a preceding case label".

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