What is the following code execution result?

    public static void main(String args[]) {
        int a = 1;
        int b = a++;
        int c = -a;
        System.out.print(a);
        System.out.print(b);
        System.out.print(c);
    }
Explanation
The following steps will be executed in order
b will be initialized with 1
a will be incremented and will be equal to 2
c will be initialized with -2

That's a fantastic trick question.

2023 Feb 17, 6:05:22 AM

Follow CodeGalaxy

Mobile Beta

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