Need Assistance?

support@tutorialshub.in

Variables, Data Types & Operators

Type Casting in Java (Widening vs Narrowing)

ADVERTISEMENT
Java Free Lesson
5 min read
ADVERTISEMENT

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
Hi, I'm Tuby! Here to help you