What is the output of the following code?
public class Main { public static void main(String[] args) { int a = 10; long b = 20; short c = 30; System.out.println(++a + b++ * c); } }
a
The prefix increment operator (++) used with the variable a will increment its value before it's used in the expression ++a + b++ * c.
The postfix increment operator (++) used with the variable b will increment its value after its initial value is used in the expression ++a + b++ * c.
Therefore, the expression ++a + b++ * c evaluates with the following values:.
11 + 20 * 30
Because the multiplication operator has a higher precedence than the addition operator, the values 20 and 30 are multiplied before the result is added to the value 11.
The example expression evaluates as follows:.
(++a + b++ * c) = 11 + 20 * 30 = 11 + 600 = 611