Which line, if any, will give a compile time error ?
void test (byte x){ switch (x){ case 'a': // 1 case 256: // 2 case 0: // 3 default : // 4 case 80: // 5 } }
Select 1 option
Correct Option is : B
A. is wrong
int value of 'a' can easily fit into a byte.
Every case constant expression in a switch block must be assignable to the type of switch expression.
For the following code:
byte by = 10; switch (by){ 300 : //some code; 56 : //some code; }
This will not compile as 300 is not assignable to 'by' which can only hold values from - 128 to 127.
This gives compile time error as the compiler detects it while compiling.
The use of break keyword is not mandatory.