Multiple type conversions means one or more type conversions perform in one program.Conversion means convert one data type to another data type.
Here is the program:
class conversion{
public static void main(String args[])
{
byte b=15; //1 Byte
short s1=b; //Byte to Short
Implicit conversion is one Byte to two Bytes.
float f=b; //Byte to Float
Implicit conversion is one Byte to four Bytes.
boolean c=true; //1 Bit
boolean d=c; //Boolean to Boolean Implicit conversion
System.out.println(s1);
System.out.println(f);
System.out.println(d);
short s=65; //2 Bytes
byte i=(byte)s; //Short to Byte
Explicit conversion is two Bytes to one Byte
char ch=(char)s; //Short to Char Two Bytes to Two Bytes It performs Explicit
conversion because it cannot be a similar type.
int q=30; //4 Bytes
short s2=(short)q; //Int to Short
Explicit conversion is four Bytes to two Bytes
System.out.println(i);
System.out.println(ch);
System.out.println(s2);
}
}
Output of Program:
Here is the program:
class conversion{
public static void main(String args[])
{
byte b=15; //1 Byte
short s1=b; //Byte to Short
Implicit conversion is one Byte to two Bytes.
float f=b; //Byte to Float
Implicit conversion is one Byte to four Bytes.
boolean c=true; //1 Bit
boolean d=c; //Boolean to Boolean Implicit conversion
System.out.println(s1);
System.out.println(f);
System.out.println(d);
short s=65; //2 Bytes
byte i=(byte)s; //Short to Byte
Explicit conversion is two Bytes to one Byte
char ch=(char)s; //Short to Char Two Bytes to Two Bytes It performs Explicit
conversion because it cannot be a similar type.
int q=30; //4 Bytes
short s2=(short)q; //Int to Short
Explicit conversion is four Bytes to two Bytes
System.out.println(i);
System.out.println(ch);
System.out.println(s2);
}
}
Output of Program:
No comments:
Post a Comment