Type Casting in Java
Type casting means changing data type of a variable. We can do type casting in Java in two ways.
- Implicit Type Casting
- Explicit Type Casting
Implicit Type Casting / Widening Casting:
This type of casting is done automatically by the Java compiler when you assign a smaller data type to a larger data type. It's also known as widening casting because you are widening the data type to accommodate a larger range of values without losing information.
Explicit Type Casting / Narrowing Casting
This type of casting is performed manually by the programmer when you want to convert a larger data type to a smaller data type.
Practice Exercises
Complete these exercises to reinforce your learning and earn XP
Sign in to track your progress and earn XP!
Exercise 1 of 2Easy
Which of the following is a best practice in programming?
10 XP~2 min
Exercise 2 of 2Easy
Code that is easy to read and understand is called ___ code.
10 XP~2 min