This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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?