• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Final Byte variable

 
Ranch Hand
Posts: 107
MyEclipse IDE Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



Q1. What is diffrence between final byte and bye variable ?
 
Ranch Hand
Posts: 276
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic