Which modification enables the code fragment to print TrueDone?

Given the code fragment: Which modification enables the code fragment to print TrueDone?

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.



Leave a Reply 9

Your email address will not be published. Required fields are marked *


marco

marco

It must be A, because the switch statement only allows variables type of: int, String and enum.

mrtsilva

mrtsilva

Correct Answer : A
Obvious that the switch statement don’t support boolean, if you wish to use boolean use a if else statement .

Kanke

Kanke

Definitely Option A

Javier Miranda

Javier Miranda

A por la puta

omar

omar

none of these options.
boolean variables are not supported to be used in switch statement.

javaexpert

javaexpert

yes..Boolean is not supported but String is supported from Java 7 onwards

Tomas

Tomas

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”);
}
}

Vendetta

Vendetta

Did exam MAY 17, 2017…This question was seen

Ans: A