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.
is there any diffrence between a=a+1 and a++. i just need to know how a++ works.Just now i gone through a code byte a=10; a++; a=a+1 second line wont give error whereas third line gives whats the reason.
* if the operand is a byte, a short or a char, it is converted to an int (unless the operator is ++ or --, in which case no conversion happens) * else there is no conversion
For binary operators, there are 4 rules:
* if one of the operands is a double, the other operands are converted to a double * if one of the operands is a float, the other operands are converted to a float * if one of the operands is a long, the other operands are converted to a long * else both operands are converted to ints
so, with the unary operator ++ or --, there is no conversion. For the + operator, it is always converted to ints (unless one of the operands is a double, float, long)
so, if you want to make your code work, you need to cast the + operation to byte