Select the valid primitive assignments of the following.
int i = 10; char c = i; float f; long l = 100L; f = l; short s = 20; char c = s; byte b = 20; char c = b; short s1 = 10; short s2 = 20; short result = s1*s2;
Joined: Mar 13, 2007
Hi sorry, posted before I was done ;-) The question that got me confused was:
Select the valid primitive assigements:
a) int i = 10; char c = i;
b) float f; long l = 100L; f=l;
c) short s = 20; char c = s;
d) byte b = 20; char c = b;
The correct answer is b). I do not understand why since float has 32 bits and float 64 bits, so how can this be done without a cast? And if it has to do with that 100 is "enough small" to fit in a float reference, why are not the other alternatives also right then since char can hold anything up to 65535?