Curriculum
Course: Java Basic
Login

Curriculum

Java Basic

Java Home

0/1

Java Introduction

0/1

Java Get Started

0/1

Java Syntax

0/1

Java Comments

0/1

Java Type Casting

0/1

Java Operators

0/1

Java Booleans

0/1

Java Switch

0/1

Java Break / Continue

0/1

Java Errors and Exception

0/1
Text lesson

default

Example

Provide instructions for code execution when no case matches within a switch block.

int day = 4;
switch (day) {
  case 6:
    System.out.println("Today is Saturday");
    break;
  case 7:
    System.out.println("Today is Sunday");
    break;
  default:
    System.out.println("Looking forward to the Weekend");
}
/ Outputs "Looking forward to the Weekend"

Definition and Usage

The “default” keyword designates the default code block in a switch statement.

It specifies instructions to execute if no case matches within the switch.

Note: If “default” is the final statement in a switch block, it doesn’t require a “break”.