(short)a=1 can't compiled?

Deal all: I am new to java. If i type as below:short a=1;b=2; ->can compiledshort a,b; a=1;b=2 -> can't compiledshort a,b;a=(short)(1);->can't compiled can anyboby tell me Why?Thanks!!!
[266 byte] By [wonwoei] at [2007-9-26 1:25:06]
# 1
Hi,A semicolon (;) is missing on the end of this line:short a,b; a=1;b=2The last one should compile. I recommend to put the statements on different lines. Also, you shouldn't explicitly cast the "1" to a short.
leukbr at 2007-6-29 1:06:08 > top of Java-index,Archived Forums,Java Programming...
# 2
IMHO explicit casting is definetly a good idea ...but just as leukbr I don't see a reason why the last line shouldn't compile ...what error message do you get?and is the line really what you are having? (it doesn't match the subject of the thread)Spieler
spieler at 2007-6-29 1:06:08 > top of Java-index,Archived Forums,Java Programming...
# 3
Sorry,i mistyped. my origin code as below: 1) :short a=1,b=2; 2) short a,b;a=1;b=2;3) short a,b;a=(short)(1);b=(short)(2);I use JDK 1.3Thank yous reply! But I still have problem!!!
wonwoei at 2007-6-29 1:06:08 > top of Java-index,Archived Forums,Java Programming...
# 4
what error are you getting now?
parthasarkar at 2007-6-29 1:06:08 > top of Java-index,Archived Forums,Java Programming...
# 5
They should work all 3 of them.Try posting the rest of your code since I think the problem is somewhere else.Otherwise, post the error as it appears on your screen.
leukbr at 2007-6-29 1:06:08 > top of Java-index,Archived Forums,Java Programming...
# 6

try this way

class test

{

//short a=1,b=2;// ->can compiled

/*short a,b;

test()

{

a=1;

b=2; //->// can't compiled

}*/

short a,b;

test()

{

a=(short)(1);//->can't compiled

}

}

aparna_chitragar at 2007-6-29 1:06:08 > top of Java-index,Archived Forums,Java Programming...
# 7

hi,

i was able to compile the below statements below with jdk 1.3.

short a=1,b=2; //->can compiled

short a,b; a=1;b=2;// -> can't compiled

short a,b;a=(short)(1);//->can't compiled

if these does not work with ur version, please do send us ur error.

regards,

shiva

shiva_jolad at 2007-6-29 1:06:08 > top of Java-index,Archived Forums,Java Programming...