About Question enthuware.ocajp.i.v8.2.908 :
Posted: Fri Jan 01, 2016 5:54 am
The correct answer is "It will not compile." not the "Exception at run time."
Java Certification Resources and Java Discussion Forum
https://enthuware.com/forum/
Code: Select all
public class Main {
public static void main(String args[]) {
int full = Integer.parseInt("20");
// Next line causes compilation error because half's value cannot be evaluated at compile time!
// final int half = full/2;
// Next line causes compilation error because half is not final!
// int half = 10;
// Next line works perfectly! A final variable with value evaluated at compile time!
final int half = 5 * 2;
switch(full/2){
case half: System.out.println("Final variable can work with case label!");
}
}
}