Implicit casting is when Java automatically converts a smaller data type into a larger one - no manual cast needed.
Order
byte β short β int β long β float β double
Example
int x = 20;
double y = x; // x β double (automatically)
System.out.println(y); // 20
Notes
- Happens automatically when moving from a smaller to a larger type
- Java handles it because thereβs no risk of losing data
- Also works with characters:
char c = 'A'; int code = c; // 'A' β 65
Tip
If the conversion goes from smaller to larger, Java handles it for you.
Parent: _Casting & Types