aspose file tools*
The moose likes Beginning Java and the fly likes Final Byte variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Final Byte variable" Watch "Final Byte variable" New topic
Author

Final Byte variable

Prakash Rai
Ranch Hand

Joined: Jan 10, 2011
Posts: 106




Q1. What is diffrence between final byte and bye variable ?
Vinoth Kumar Kannan
Ranch Hand

Joined: Aug 19, 2009
Posts: 276

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.


OCPJP 6
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Final Byte variable