Implicit Type Casting: when the two data types are compatible and also when we assign the value of a smaller data type to a larger data type.
public class ImplicitTypeCasting
{
public static void main(String[] args)
{
int i = 10;
double d = i; //implicit type casting
System.out.println("Int value "+i);
System.out.println("Double value "+d);
}
}
Explicit Type Casting: or narrowing casting in Java is done manually. When we want to convert a larger type to the smaller type size then we use explicit type casting.
public class ExplicitTypeCasting
{
public static void main(String[] args)
{
double d = 10.086;
long l = (long)d; //explicit type casting
int i = (int)l; //explicit type casting
System.out.println("Double value "+d);
System.out.println("Int value "+i);
}
}