Meaningless Drivel is fun!
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Operators and Assignment" Watch "Operators and Assignment" New topic

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
public class b1{
public static void main(String arg[]){
final int i=10;
byte b=i;// will compile
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: 129
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
Which version of compiler are you using?
JDK1.3.1 or later should compile following code without problem:

I agree. Here's the link:
subject: Operators and Assignment
It's not a secret anymore!