PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

Java · Theory

Java Switch Statement

← All stacks

Theory

17/270

Java Switch Statement

switch picks one case from many options using one value — day number, menu choice, grade letter. You write switch(value), then case labels.

The matching case runs until break (or the end of switch). If you forget break, the next case also runs. That is called fall-through. default is like else: no case matched.

switch is cleaner than a long else-if chain when the value is a fixed list. It works with int, String, enum, and more in modern Java.

Interviewers almost always ask about missing break. Say it out loud: without break, cases fall through.

Let's take this on the board with one tiny Main class — no extra files. Java Switch Statement — day is 2, so case 2 prints Tue. break leaves the switch — case 1 and default do not run. Remove break and Tue + Other would both print (fall-through). Start from main, go line by line, and stop at each print. That output is the proof for Switch Statement.

Diagram
switch(day)
    case 1 → Mon  + break
    case 2 → Tue  + break
    default → Other
Exam tip

Explain break and fall-through with a 3-case example.

Example

// Java Switch
public class Main {
  public static void main(String[] args) {
    int day = 2;
    switch (day) {
      case 1:
        System.out.println("Mon");
        break;
      case 2:
        System.out.println("Tue");
        break;
      default:
        System.out.println("Other");
    }
  }
}

Java Switch Statement — day is 2, so case 2 prints Tue. break leaves the switch — case 1 and default do not run. Remove break and Tue + Other would both print (fall-through).

Short notes

  • Defswitch picks one case from many options using one value.
  • RuleMatching case runs until break. default is the fallback.
  • TrapMissing break → fall-through (later cases also run).
  • Useday number, menu, grade letter.

Questions

1

When do you use switch?

2

What does break do in switch?

3

What is fall-through?

4

What is default?

Previous← Java If-else StatementNextJava For Loop →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.