File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes q 25 from tipsmart.com Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "q 25 from tipsmart.com" Watch "q 25 from tipsmart.com" New topic
Author

q 25 from tipsmart.com

jake noi
Greenhorn

Joined: Jan 07, 2001
Posts: 6
From TipSmart's sample paper
class MyClass
{
public static void main(String []args)
{
final int i = 100;
byte b = i;
System.out.println(b);
}
}
Here is the answer from website => Will compile and print 100
How come that we don't need to explicitly cast from int to byte?
Thank you for your clarification
Michael Burke
Ranch Hand

Joined: Jul 29, 2000
Posts: 103
Because the int is final and so is a constant. The compiler can figure out the value at compile time and since 100 fits into a byte the compiler allows it. Anyone else want to clarify?
Vladimir Kositsky
Ranch Hand

Joined: Nov 03, 2000
Posts: 116
My compiler issued approval
It does not compile without final
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: q 25 from tipsmart.com
 
Similar Threads
can someone expalin the output ???
Problem with this code
Rule about final?
automatic primitive conversion from higher to lower precision?????
why do final variables not need a cast?