Which line rests on a mistaken assumption?
public class Sample31
{
public static void main(String[] args)
{
int big = Integer.MAX_VALUE;
assert big + 1 > big : "overflow";
System.out.println(big + 1);
}
}
Answer: C
Adding one to Integer.MAX_VALUE wraps silently to Integer.MIN_VALUE, so the sum is negative and the assertion that it exceeds the original is false. The assumption that addition always increases an int is the mistake; Java does not raise an error on overflow.
Please log in or register to report this question.