This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Operators and Assignment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Operators and Assignment" Watch "Operators and Assignment" New topic
Author

Operators and Assignment

Arathi Rajashekar
Ranch Hand

Joined: Nov 20, 2001
Posts: 112
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).]


Arathi<br />Sun Certified Java Programmer
Darryl Failla
Ranch Hand

Joined: Oct 16, 2001
Posts: 128
final short j=10;
This compiles and runs properly for me.


Darryl Failla
Sun Certified Java 2 Programmer
Nain Hwu
Ranch Hand

Joined: Sep 16, 2001
Posts: 139
Arathi,
Which version of compiler are you using?
JDK1.3.1 or later should compile following code without problem:

 
Don't get me started about those stupid light bulbs.
 
subject: Operators and Assignment
 
Similar Threads
Assignment doubt
static variable vs final variable!
wrapper classes
final int/byte
narrowing convertion in case of final