🎴 Flashcard Mode

programming languages Online Quiz - 128

Card1 / 20
Mastered0
Review0
QuestionClick to flip

What will be printed out if you attempt to compile and run the following code? int i=9; switch (i) { default: System.out.println("default"); case 0: System.out.println("zero"); break; case 1: System.out.println("one"); case 2: System.out.println("two"); }

AnswerClick to flip back
A
default, zero
💡 Explanation:

Since i is 9, it matches no explicit case, transferring control to the default block. Because there is no break statement at the end of the default block, execution falls through to execute case 0 print statement, outputting both 'default' and 'zero'.

Change Mode