Type casting is the conversion from 1 data type to another.
It is of 2 types :
1. Widening
2. Narrowing
Widening
In case of widening, we convert smaller datatype like an integer to bigger data type like double.
int a = 4;
double b = a;
System.out.println(b);
Output
4.0
Narrowing
In case of narrowing we convert bigger datatype like double to smaller data type like an integer.
double c = 3.445;
int d = (int) c;
System.out.println(d);
Output:
3
Conclusion:
Here, we learned about Type Casting. In the next article, we’ll learn about operators.