What will be the result of compilation and execution of the following code?

public class Main {
    static int a, b;
    public static void main(String[] args) {
        if (!(++a==0 && ++b==0)) System.out.print("true a+b=");
        else System.out.print("false a+b=");
        System.out.print(a + b);
    }
}
Explanation
&& is a "short-circuit" operator, ++a==0 is evaluated to false, therefore ++b is never executed.

Follow CodeGalaxy

Mobile Beta

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