Type Casting and Conversion

Type casting is converting one data type into another.

Types:

  • Implicit Casting (Widening): Java automatically converts smaller data types to larger ones.
    int x = 10;
    double y = x; // int to double
  • Explicit Casting (Narrowing): Requires manual conversion.
    double a = 10.5;
    int b = (int) a; // double to int
← PrevNext →