Oracle Certified Associate Java Se 8 Programmer · Free Practice Question Hard
Question 48
Consider the following code:
- public class Test
- {
- public static void main(String[] args)
- {
- byte b = 10;
- switch(b+1)
- {
- case 10: System.out.print(10);
- case 100: System.out.print(100);
- case 1000: System.out.print(1000);
- }
- }
- }
What is the result?
-
A
10100
-
B
10
-
C
Nothing will be printed to the console.
-
D
101001000
Reveal correct answer
Correct answer: C
Explanation
Every case label should be within the range of switch argument type. In the above code switch argument 'b+1' is of int type. All case labels are within the range only. Hence we won't get any compile time error. But no case is matched and hence we won't ger any output.Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
You must be logged in to post a comment.
