Wednesday, May 30, 2018

Type Conversion and Casting using JAVA

If you have previous programming experience, then you already know that it is fairly
common to assign a value of one type to a variable of another type. If the two types are
compatible, then Java will perform the conversion automatically. For example, it is
always possible to assign an int value to a long variable. However, not all types are
compatible, and thus, not all type conversions are implicitly allowed. For instance,
there is no conversion defined from double to byte. Fortunately, it is still possible to
obtain a conversion between incompatible types. To do so, you must use a cast, which
performs an explicit conversion between incompatible types. Let’s look at both automatic
type conversions and casting.
banner
Previous Post
Next Post

0 comments: