File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

q 25 from tipsmart.com

 
jake noi
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 103
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 116
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My compiler issued approval
It does not compile without final
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic