posted 11 years ago
1) short can fit in double. When I assign "d = s3" , I am getting error "Syntax error on token ";", , expected" on the line immediately before this assignment (int s3 = s2). If I comment "d = s3", this error is gone. Whats wrong with this assignment ? I am getting same error, if I do "s2 = s1" or "f = s2"
This error does not come, if I am creating new declaration. "float f5 = s2" works fine.
So, once a primitive variable is declared, can it be not be assigned value in the same scope ? Does it have to be assigned a value in a method only ? When I assign s2 = s1 in aMethod, it works fine.
2) Another thing is, long l takes more bytes than float f5. But when I assign "f5 = l", I don't get type cast error. Why is that ? If I do "i = l" , I immediately get type cat error. Why do I not get type cast error for assigning a float variable a value of a long ?
Thanks