About Question enthuware.ocpjp.v7.2.1230 :
Posted: Mon Jun 29, 2015 3:04 pm
FYI : case labels must be compile time constants. Thus, you cannot use non-final variable names as labels. final variables can be used.
OK:
public int m3(String a, int b) {
final String c = "a";
switch (a) {
case c:
return 1;
}
return 0;
}
Error:
public int m3(String a, int b) {
final String c = a;
switch (a) {
case c:
return 1;
}
return 0;
}
The statement "Thus, you cannot use non-final variable names as labels. final variables can be used." must be removed .
OK:
public int m3(String a, int b) {
final String c = "a";
switch (a) {
case c:
return 1;
}
return 0;
}
Error:
public int m3(String a, int b) {
final String c = a;
switch (a) {
case c:
return 1;
}
return 0;
}
The statement "Thus, you cannot use non-final variable names as labels. final variables can be used." must be removed .