Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Final Byte variable

 
Prakash Rai
Ranch Hand
Posts: 106
Eclipse IDE MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



Q1. What is diffrence between final byte and bye variable ?
 
Vinoth Kumar Kannan
Ranch Hand
Posts: 276
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the first case, when adding two byte variables, internally they are being promoted to int and so the result is an int, which you must cast back to a byte - because in Java for an arithmetic operation to be performed, the operands must be atleast an int.
In the second case, since you are adding two final byte variables, Java compiler knows that you cannot change them in future and so it performs addition at the compile time itself and assigns it to b7. Here the promoting to int & casting to byte - all are done internally at the compiling stage itself.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic