• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Operators and Assignment

 
Arathi Rajashekar
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have question.Just check the following code
public class b1{
public static void main(String arg[]){
final short s=10;
byte b=s; //will not compile. say casting is required
System.out.println(b);
}
}
whereas
public class b1{
public static void main(String arg[]){
final int i=10;
byte b=i;// will compile
System.out.println(b);
}
}
why is it so. Can anybody explain the reason.

[This message has been edited by Arathi Rajashekar (edited November 29, 2001).]
 
Darryl Failla
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
final short j=10;
This compiles and runs properly for me.
 
Nain Hwu
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arathi,
Which version of compiler are you using?
JDK1.3.1 or later should compile following code without problem:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic