This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
I am using switch and case statements. It is indicated in Bill Brogden's book, 'Exam Prep' that, "Each case must specify an integer constant followed by a colon."(p141) I understand this; but I tried using a character instead of an integer in a case statement (like case 'A') and it ran fine. Am I to assume that characters are interpreted as constant integers?
From Mughal: "The type of the integral expression must be char, byte, short or int. The case label values must be assignable to the type of the integral expression." Hope this helps. ------------------
As Adrian said, it must be of type integral. case 'A' can be converted to an int value, so it is ok. Final variables and expressions like case 1+4 are ok also because the compiler knows those values. Ask yourself will the compiler be able to determine the value of the case statement at compile time and is the value an int or able to be converted to an int (byte, char, short, or int).