aspose file tools*
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
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how this works?