Given the code fragment: Which modification enables the code fragment to print TrueDone?
A.
Replace line 5 With String result = “true”; Replace line 7 with case “true”:
B.
Replace line 5 with boolean opt = l; Replace line 7 with case 1=
C.
At line 9, remove the break statement.
D.
Remove the default section.
It must be A, because the switch statement only allows variables type of: int, String and enum.
Correct Answer : A
Obvious that the switch statement don’t support boolean, if you wish to use boolean use a if else statement .
Definitely Option A
A por la puta
none of these options.
boolean variables are not supported to be used in switch statement.
yes..Boolean is not supported but String is supported from Java 7 onwards
Answer: A
Tested
code:
public class Test21 {
public static void main(String[] args) {
String opt = “true”;
switch(opt){
case “true”:
System.out.print(“True”);
break;
default:
System.out.print(“***”);
}
System.out.println(“Done”);
}
}
a
Did exam MAY 17, 2017…This question was seen
Ans: A