Widening of Variables in java :
Widening of variable in java means promotion (or conversion) of small primitive type value to bigger primitive type value. it is also known as uppercasing.. Java do this conversions automatically so also known as automatic conversion.
Like :
byte value to int value.
short value to int value.
int value to long value.
Example:
Result:
This Automatic Conversions happens only When
1) When we assign Smaller Primitive value to Big primitive value.
Example :
int primitive Assigns to float primitive
2)Both Premitive Data types Compatible to each other
Example :
byte primitive to char primitive
boolean data type does not support widening because it doesnot hold numeric value,It holds only true or false
Sequence of primitive data types smaller to bigger
Widening of char primitive to byte:
char and byte primitives are both are compatible of each other. both can be widen each other
Example :
Result:
unicode for character 'A' is 65 so by widening char to byte value of Character not changed
References :
https://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.1.3
https://www.geeksforgeeks.org/type-conversion-java-examples/