Java Widening Casting

Java Widening Casting


Widening or Automatic Type Conversion, Or  Implicit type casting - 
As the name suggests Narrowing or Explicit conversion is a predefined conversion it is done by the compiler, not the programmer.
Widening conversion takes place when two data types are automatically converted. This happens when:  The two data types are compatible.  When we assign the value of a smaller data type to a bigger data type. For Example, in java, the numeric data types are compatible with each other but no automatic conversion is supported from numeric type to char or boolean. Also, char and boolean are not compatible with each other.
Byte -> Short -> Int -> Long - > Float -> Double
Widening or Automatic Conversion
Example of Implicit or automatic conversion
 
class Main {
  public static void main(String[] args) {
    // create int type variable
    int num = 10;
    System.out.println("The integer value: " + num);

    // convert into double type
    double data = num;
    System.out.println("The double value: " + data);
  }
}