Java Narrowing Casting

Java Narrowing Casting


Narrowing or Explicit Conversion, Or Explicit type casting - 
As the name suggests Narrowing or Explicit conversion is not predefined conversion it is done by the programmer, not the compiler.
If we want to assign a value of a larger data type to a smaller data type we perform explicit type casting or narrowing. 
This is useful for incompatible data types where automatic conversion cannot be done.  Here, the target type specifies the desired type to convert the specified value to.
Double-> Float -> Long-> Int - > Short ->Byte
Narrowing or Explicit Conversion
Example of Narrowing type conversion-
 
class T{
  public static void main(String[] args) {
    // create int type variable
    int num = 29;
    System.out.println("The integer value " + num);

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