aspose 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
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: q 25 from tipsmart.com