byte x = 0;
byte y = (--x<0) ? ++x : -x;
System.out.println(y);
Result of the code execution will be:
Explanation
Expression result will have type int, because the type of the third operand of the ternary operator in the result will be int. Therefore, you need explicit conversion for successful compilation.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes