What will be the value of y after executing the following statements:

int x = Integer.MIN_VALUE;
int y = -x;
Explanation
When applied to x unary operator - returns a value of 0-x. But value y=2147483648 (which is 0b10000000000000000000000000000000 ) will not fit into the range of type int as a positive value: due to it's first bit it will be considered as a negative value, and will be equal to x. Therefore, y=-x, y=x --> x=-x
Java
Java Quiz
Start Quiz

or Read more about Java Quiz

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback