What will be displayed, if the following code is compiled and executed:

public class Main {
    public static void main(String args[]) {
        System.out.println("2 + 2 = " + 2 + 2);
    }
}
Explanation
Actions are executed in order from left to right. Due to the fact that the string is the first operand, the concatenation is performed.
In order to get a mathematically correct example, you can modify the order of operations execution with the help of parentheses:
System.out.println("2 + 2 = " + (2 + 2));
Java
Java Quiz
Start Quiz

or Read more about Java Quiz

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback