Computer Applications
Which of the following is true about the default
label in a switch
statement?
Java Conditional Stmts
1 Like
Answer
It executes if no matching case label is found.
Reason — The default
label in a switch
statement is used as a fallback option. If none of the case
labels match the switch
expression, the default
block executes.
- Including a
default
label is optional in aswitch
statement. - It can appear anywhere within the
switch
block. - The
default
label can appear only once, but its position within theswitch
block is flexible (not restricted to the top).
Answered By
3 Likes
Related Questions
Which of the following data type cannot be used with switch case construct?
- int
- char
- String
- double
Write a Java program to print name, purchase amount and final payable amount after discount as per given table:
Purchase Amount Discount upto ₹10000/- 15% ₹10000 to ₹ 20000/- 20% Above ₹20000/- 30% Write a program to input three numbers (positive or negative). If they are unequal then display the greatest number otherwise, display they are equal. The program also displays whether the numbers entered by the user are 'All positive', 'All negative' or 'Mixed numbers'.
Sample Input: 56, -15, 12
Sample Output:
The greatest number is 56
Entered numbers are mixed numbers.Which of the following is not true with regards to a switch statement?
- checks for an equality between the input and the case labels
- supports floating point constants
- break is used to exit from the switch block
- case labels are unique