What will be printed out to console as a result of the following code execution?

public class Clazz {
    public static void main(String[] args) {
        int a = 0;
        System.out.println("a=" + new Integer(a = 1));
    }
}
Explanation
a = 0 initially. The assignment operator "=" has the following form, speaking abstractly,
int operator_= (int n){ return n; }
Therefore, (a = 1) returns 1, which is passed to the constructor of the Integer class

Follow CodeGalaxy

Mobile Beta

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