Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 6th, 2012  |  syntax: None  |  size: 0.29 KB  |  hits: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Why no overflow when byte exceeds size? [closed]
  2. public static void main(String[] args) {
  3.     byte b = 127;
  4.     ++b;
  5.     System.out.println(b);
  6. }
  7.        
  8. int c = 2147483647;
  9. ++c;
  10. System.out.println(c);
  11.        
  12. byte b = 127;
  13. byte oldb = b;
  14. b++;
  15. if( b < oldb ) {
  16.     // Calamity!!!  Raise an exception!
  17. }