one data type converts into another Data Type is called Type Casting.
There are 2 types
1. Implicit.(Widening conversion) or (Up casting)
2. Explicit.(Narrowing conversion) or (down casting)
Implicit casting: Automatic casting done by the java compiler internally is called implicit casting. Implicit casting is done to convert a lower data type into a higher data type.
Class implicit {
Public static void main(String args[] )
{
int a;
byte b=10;
a=b;
System.out.println(a);
System.out.println(b);
}
}
Explicit casting: The casting done by the programmer is called explicit casting. Explicit casting is compulsory while converting from a higher data type to a lower data type.
Class explicit {
Public static void main(String args[] )
{
int a=10;
byte b;
b=(byte) a;
System.out.println(a);
System.out.println(b);
}
}