class P04_intOverflow { public static void main(String[] args) { //int type can hold 2123123123. However, 2123123123+2123123123 is too big for int. System.out.println(2123123123); //Output is OK: 2123123123 long x; x = 2123123123 + 2123123123; System.out.println(x); //Wrong Output: -48721050 } } /* Question: x is long. Why the result is still overflow? Answer: * First step : "2123123123 + 2123123123" * Second step : set the value of x * Here, the data type of x is not concerned in the first step. That is, whether x is int or long, does not affect the first step. Because nNumbers like "2123123123" is by default treated as int. Therefore "2123123123 + 2123123123" is operated in int mode. */