Introduction
Typecasting is a technique in which we convert one type of value into another type of value. There are two types of typecasting.
1. Narrowing
2. Widening
Narrowing:
To remove this error we must explicitly typecast.
- class Narrowing {
- public static void main(String… args) {
- int I;
- double d = 1.0;
- i = (int) d;
- System.out.print(i);
- }
- }
Widening:
- class Widening {
- public static void main(String… args) {
- int I = 5;
- double d;
- d = i;
- System.out.print(d);
- }
- }

Join the conversation! Your thoughts help the community grow.