All, This one may look easy for some. But at first sight it is confuses. Try the following.
int i=10;
// Following need explicit cast in order to get compiled.
char c=i; byte b=i; short s=i;
//But Following works fine - compiles well.
char c=10; byte b=10; short s=10;
My school of thought would say : As long as the value of RHS is in range of the LHS type, it should not need explicit cast no matter RHS is a variable or value.
Would someone please justify this behaviour of JVM!!!
Another thing - in a mockexam (
http://valiveru.tripod.com/java/jvaltest.html) the following declaration is said valid. (which I tested does NOT compile)
int i=10; char c=i;
Are these site authenticated? This site has very tough Qs and added to that couple of wrong answers like above.
Testing yourself at these site might be frustrating. Just a breather to concerned ones.