0

Type promotion of expression in java

Type promotion of expression in java

In an expression the precision required of an Intermediate value will sometimes exceed the range of other operand
For example

expression (a*b) easily exceed the range of its byte operand.Thus,
java promote each byte, short and char operand to int This means that the subexpression (a*b) is performed using integers not byte.
Type promoting Rules:-

1 All byte,short and char value are promoted to int
2. If one expression is long the whole expression is promoted to long
3. If one expression is double the whole expression is promoted to double

Capture
in the first subexpression (a*e) a is promoted to float and the result of subexpression is float,Next subexpression (f*b) b is promoted to int,and the result of subexpression is int and the Next one subexpression (d*c) c is promoted to
double thus the first (a*e) and second (f*b) addition is promoted to float,subtract with the third subexpression (d*c)
is the result is promoted to double which is the type for the final result of the subexpression

Pravesh Kumar

Leave a Reply

Your email address will not be published. Required fields are marked *