MCQ Single Best Answer Moderate

QWhich statement allows for multiple selections in Java?

ID: #24859 Control flow in programming 4 views
Question Info
#24859Q ID
ModerateDifficulty
Control flow in programmingTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A if
  • B switch
  • C for
  • D while
Correct Answer: Option B

Explanation

(b) switch

The switch statement is used when a variable can have multiple possible choices or cases. It helps make the code cleaner and easier to read compared to using many if-else statements.

Example:


switch(day) {
    case 1:
        System.out.println("Monday");
        break;

    case 2:
        System.out.println("Tuesday");
        break;

    default:
        System.out.println("Invalid Day");
}

Share This Question

Challenge a friend or share with your study group.