thank you kumar for such a fast reply.. so if the the variables are compile constants you assign a short variable which is final to a byte...doesn't this need explict casting..i am little confused in this topic please expalin..
Implicit narrowing primitive conversions on assignment can occur in cases where all of the following conditions are fulfilled:
1. The source is a constant expression of either byte, short, char , or int type 2. The destination type is either byte, short, or char type. 3. the value of the source is determined to be in the range of the destination type at compile time.
class Black { public static void main(String[] args) { short s1 = 1; //1 char c1 = 1; //2 byte b1 = s1; //3 here value of source(s1) is in the range of destination(byte). but (s1) is not a constant ( not final),no implicit casting byte b2 = c1; //4 same final short s2 = 1; //5 final char c2 = 1; //6 byte b3 = s2; //7 source s2 is a constant (final) and value of source(s2) is in the range of destination (b3-byte) byte b4 = c2; //8 source c2 is a constant (final) and value of source (c2-char, promoted to int) is with in the range of destination (b4-byte) }}
Hope this helps u Regards Naresh
We begin by testing your absorbancy by exposing you to this tiny ad:
a bit of art, as a gift, that will fit in a stocking