Wednesday, May 30, 2018

Automatic Conversions in JAVA

When one type of data is assigned to another type of variable, an automatic type
conversion will take place if the following two conditions are met:
■ The two types are compatible.
■ The destination type is larger than the source type.
When these two conditions are met, a widening conversion takes place. For example,
the int type is always large enough to hold all valid byte values, so no explicit cast
statement is required.
For widening conversions, the numeric types, including integer and floating-point
types, are compatible with each other. However, the numeric types are not compatible
with char or boolean. Also, char and boolean are not compatible with each other.
As mentioned earlier, Java also performs an automatic type conversion when
storing a literal integer constant into variables of type byte, short, or long.
banner
Previous Post
Next Post

0 comments: