Java Primitive Conversion
Chapter:
Miscellaneous
Last Updated:
21-10-2016 13:20:35 UTC
Program:
/* ............... START ............... */
public class JavaPrimitiveConversion {
public static void main(String[] args) {
System.out.print("Y" + "O");
System.out.print('L' + 'O');
}
}
/* ............... END ............... */
Output
Notes:
-
In double quotes, the text is treated as a string and “YO” is printed, but when we use single quotes, the characters ‘L’ and ‘O’ are converted to int. This is called widening primitive conversion. After conversion to integer, the numbers are added ( ‘L’ is 76 and ‘O’ is 79) and 155 is printed.
Tags
Primitive Conversion, Java, Miscellaneous