Page 1 of 1
About Question enthuware.ocajp.i.v8.2.1314 :
Posted: Tue Jun 25, 2019 12:47 pm
by vilasa
One of the answer is Conversion from byte to short doesn't need a cast. I tried testing this.But it gives compiler error sayin incompatible types
byte by1=10;
s=by1;
error: incompatible types: byte cannot be converted to Short
s=by1;
^
1 error
Thanks,
Veena
Re: About Question enthuware.ocajp.i.v8.2.1314 :
Posted: Tue Jun 25, 2019 7:34 pm
by admin
Please post the complete and exact code that you are trying to compile. From the error message, it looks like you are using Short instead of short.
Re: About Question enthuware.ocajp.i.v8.2.1314 :
Posted: Thu Jun 27, 2019 10:39 pm
by vilasa
You are right. It was Short ,not short. Thank you.
Re: About Question enthuware.ocajp.i.v8.2.1314 :
Posted: Sat Nov 16, 2019 9:47 am
by girishankaran
Conversion from char to long does not need a cast. the answer is true or false?
Its shows true
Re: About Question enthuware.ocajp.i.v8.2.1314 :
Posted: Sat Nov 16, 2019 11:38 am
by admin
What happened when you tried it out?
Re: About Question enthuware.ocajp.i.v8.2.1314 :
Posted: Sun Feb 07, 2021 11:12 am
by jeroenisanders
Conversion from int to float does need a cast. The opposite is not true. For instance next will not compile:
float fll = 1;
int int23 = 2;
int23 = fll;
Re: About Question enthuware.ocajp.i.v8.2.1314 :
Posted: Sun Feb 07, 2021 10:14 pm
by admin
jeroenisanders wrote: ↑Sun Feb 07, 2021 11:12 am
Conversion from int to float does need a cast. The opposite is not true. For instance next will not compile:
float fll = 1;
int int23 = 2;
int23 = fll;
No, conversion from int to float DOES NOT need a cast. conversion from float to int needs a cast.
That is why, in your example, the first line compiles fine. The third line does not.
Re: About Question enthuware.ocajp.i.v8.2.1314 :
Posted: Sat Jun 04, 2022 8:23 pm
by herngyih
"Conversion from short to char needs a cast". The reason given is because their ranges are not compatible. Both are 16 bits though.
1.Is it because char is unicode and short is integral?
2.Notice that byte is 8 bits and yet still need casting to fit into char(16 bits).Why?
Code: Select all
byte bytey =1;
char chary = 'a';
chary = bytey; //fail
chary = (char)bytey; //OK
Re: About Question enthuware.ocajp.i.v8.2.1314 :
Posted: Sat Jun 04, 2022 9:21 pm
by admin
No, it is because short can have negative values while char cannot. byte, char, short, int , and long are all integral types.