File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes q 25 from 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" Watch "q 25 from" New topic

q 25 from

jake noi

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;
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:
subject: q 25 from
It's not a secret anymore!