Numeric Promotion Rules
int num =1; // default int
long longNum = 23L; // long Literal
// rule 1 -> promote values to larger data type
long imLong = num + longNum;
If same datatype -> resulting value will have same datatype.
float num1= 2300000000F;
float num2= 55000000000000F;
float num3 = num1 * num2;
floating value and integral value operation promotion
long longNum = 23; // integral
float floatNum= 1000F; // floating
//promote longNum value to floating point value's data type(float in this case).
float z = longNum * floatNum;
byte byteNum= 5;
short shortNum = 2;
// both will be promoted to int first before the actual operation.
int result = byteNum * shortNum;
byte byteNum= 5;
short shortNum = 2;
// both will be promoted to int first before the actual operation.
int result = (short)byteNum * (short)shortNum;
// compile time error lossy conversion
short shortResult = (short)byteNum * (short)shortNum;
byte byteNum= 5;
short shortNum = 2;
// after promotion to int and returning int. we can now cast it to short
short result = (short) (byteNum * shortNum);