Found this on a mock exam site.....
public class ADirtyOne
{
public static void main(
String args[])
{
System.out.println(Math.abs(Integer.MIN_VALUE));
}
}
an attempt to compile and run the above class will
1. Cause a compiler error.
2. Cause no error and the value printed on the screen is less than zero.
3. Cause no error and the value printed on the screen is one more than Integer.MAX_VALUE
4. Will throw a runtime exception due to overflow - Integer.MAX_VALUE is less in magnitue than Integer.MIN_VALUE.
The answer given is surprisingly 2. I copiled and checked the answer and it is correct. What I do not understand is how is the Math.abs() method returning a -ve value.....
Any inputs???
Thanks,
Shafeeq