Java Reference
In-Depth Information
the range of a short because its high-order bits are removed. When a floating-point value
is cast to an integer type, the fractional component will also be lost due to truncation. For
example, if the value 1.23 is assigned to an integer, the resulting value will simply be 1.
The 0.23 is lost.
The following program demonstrates some type conversions that require casts:
The output from the program is shown here:
In the program, the cast of (x / y) to int results in the truncation of the fractional com-
ponent, and information is lost. Next, no loss of information occurs when b is assigned the
Search WWH ::




Custom Search