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.
You're taking a char literal and adding it to an int and printing the result. Remember that all integer addition with byte, char, and short is promoted to int. The int value of 'a' is 97 so it adds 1 to 97 and prints the answer. In the second two lines:
char y = 'a' + 1; System.out.println( y);
You're doing the addition in the first line and then putting it back into a char, then printing the char, not an int. Keep in mind that this onlyworks without a cast because your using literals. If you did this it wouldn't compile:
Hi Cundra, No you wouldn't get a compiler error because the 'a' + 1 is taken as a literal value by the compiler. In other words the 'a' + 1 is replaced by 98 by the compiler. So the compiler really sees: c = 98; which is a valid statement! Regards, Manfred.