Mega Code Archive

 
Categories / Java Book / 001 Language Basics
 

0086 Automatic Type Promotion in Expressions

For example, examine the following expression: public class Main { public static void main(String[] argv) { byte a = 40; byte b = 50; byte c = 100; int d = a * b / c; } } The result of a * b exceeds the range of byte. To handle this kind of problem, Java automatically promotes each byte or short operand to int. a * b is performed using integers.