This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
hi, i have just solved a mock exam.i am doubtful for a question.the question was True/False "In a swith statement,the argument to the case label(case:argument) can be any variable which can fit within an int."
As per my knowledge,the allowable value for the case label can be of integral type ie: char,short,byte & int. so the ans for this question could be true. but the ans given is false and the explanation given is " The case argument must be either an int literal or an int compatible variable which is constant (ie: static final) " Can anybody help me with the clarification of these question/ans.This is a bit Urgent Thanks in advance. -Vrunda Divekar
From JLS 14.10 The switch Statement The type of the Expression must be char, byte, short, or int, or a compile-time error occurs. The problem here is that a long primitive like 12L fits perfectly within an int but a long is not allowable in a case expression. If you try to compile the following code
it gives you the following error:
[ June 12, 2002: Message edited by: Valentin Crettaz ]