This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes how this works? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "how this works?" Watch "how this works?" New topic
Author

how this works?

kavita s. kumar
Greenhorn

Joined: Oct 26, 2001
Posts: 16
hi
the following ode doesn't give any error..how byte accepts an int

public class AnotherDirtyOne
{
private final int i =10;
private byte k = i;
}

thans in advance
Kavita
hai zhang
Greenhorn

Joined: Oct 30, 2001
Posts: 11
You can assign an integer literal to a byte or short variable if the literal falls within the range of the variable.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
here you don't assign a literal but a variable, Hai !
The only reason why this works is because the variable i is declared final and the compiler knows the value it holds. Try removing the final keyword and it doen't work anymore !
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
 
 
subject: how this works?