byte to short Java

byte to short Java


After knowing the Java rules of Data Type Casting (Type Conversion), let us cast byte to short. The byte takes 1 byte of memory and short takes two bytes of memory. Assignment 1 byte value to 2 bytes is done implicitly by the JVM.

byte –> short –> int –> long –> float –> double

The left-side value can be assigned to any right-side value and is done implicitly. The reverse requires explicit casting.

Examples:

Following example on byte to short illustrates the syntax of automatic promotion of widening conversion of Java.


byte to short
Output screenshot of byte to short Java

1 byte value b1 is assigned to 2 bytes s1 and is type casted implicitly.

View all for 65 types of Conversions

Leave a Reply

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