Wednesday, March 23, 2022

Widening vs Narrowing in Java

The process of changing a value from one data type to another type is known as data type conversion. Two types

  • Widening
    //int is converted to long
    int i = 10; 
    long l = i; //implicit type casting
    
  • Narrowing
    double d = 10.02;
    int l = (int) d; //explicit type casting

 

No comments:

Post a Comment