Type Casting converts a value from one primitive data type to another:
- Widening (Implicit) Casting: Converting a smaller type to a larger type (
byte → short → int → long → float → double). Safe and automatic—no data loss. - Narrowing (Explicit) Casting: Converting a larger type to a smaller type (
double → int). Must be done manually with parentheses(int)because decimal digits or overflow bits may be truncated.
ADVERTISEMENT