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

- 04-04-2012, 09:27 PManubhavm5164type converison
why can we write

short a=9;

We know that 9 is integer and int cant be assigned to short...loss of precision... - 04-04-2012, 09:34 PMKevinWorkmanRe: type converison
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." - 04-04-2012, 09:38 PManubhavm5164Re: type converison
but character is not an integral type..

still we can write

char ch=66; - 04-04-2012, 09:58 PMKevinWorkmanRe: type converison
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. - 04-04-2012, 10:04 PManubhavm5164Re: type converison
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... - 04-04-2012, 10:41 PMDarrylBurkeRe: type converison
char

**is**an integral type. See the JLS: Chapter*4.*Types, Values, and Variables

db