java - casting or data type conversion of primitive values -


a) if write in java

short = 15 short b = 3; short c = * b;//will not compile  know not compile because short values automatically promoted int resulting value of type int compile:  int d=a*b ; //compile 

b)if multiplication of long numbers such as:

long a=15; long b=3; long c=a*b;//will compile int d=a*b;//will not compile 

i assume long values not promoted int because int smaller,but when write

long a=15;

java have interpreted literal int because there no 'l' 15 in assignment,if java had interpreted int why can't multiply interpreting of int data types

int d=a*b;  

why should give error?

does java not take consideration int value in case of arithmetic operation of long variables ?

why java allows long a=15; interpreting int when can't operation on int .

this due fact java converts upwards not downward. convert bigger adding space reducing space might have loss of data therefore java not it. take small number 15 long waste of memory if never going fill in space long uses.


Comments