why can we write
short a=9;
We know that 9 is integer and int cant be assigned to short...loss of precision...
Printable View
why can we write
short a=9;
We know that 9 is integer and int cant be assigned to short...loss of precision...
Recommended reading: Primitive Data Types (The Java™ Tutorials > Learning the Java Language > Language Basics)
"Values of the integral types byte, short, int, and long can be created from int literals."
but character is not an integral type..
still we can write
char ch=66;
Same principle applies. I'm really not sure what your question is? The fact is that we can do it this way. Asking why is a bit moot.
See , what I am trying to ask is that....
66 is by default integer...
if we assign an integer to char, its loss of precision..
wat u told that byte, short initial values can be created from int literals..fyn..but..is the same applies for char...
char is an integral type. See the JLS: Chapter*4.*Types, Values, and Variables
db