Java Reference
In-Depth Information
This program produces the output:
k==25 and a[0]==25
The value 1 of k is saved by the compound assignment operator += before its right-
hand operand (k = 4) * (k + 2) is evaluated. Evaluation of this right-hand operand then
assigns 4 to k , calculates the value 6 for k + 2 , and then multiplies 4 by 6 to get 24 . This
is added to the saved value 1 to get 25 , which is then stored into k by the += operator.
An identical analysis applies to the case that uses a[0] .
In short, the statements:
k += (k = 4) * (k + 2);
a[0] += (a[0] = 4) * (a[0] + 2);
behave in exactly the same manner as the statements:
k = k + (k = 4) * (k + 2);
a[0] = a[0] + (a[0] = 4) * (a[0] + 2);
15.27. Expression
An Expression is any assignment expression:
Expression:
AssignmentExpression
Unlike C and C++, the Java programming language has no comma operator.
15.28. Constant Expressions
ConstantExpression:
Expression
A compile-time constant expression is an expression denoting a value of primitive type or
a String that does not complete abruptly and is composed using only the following:
• Literals of primitive type and literals of type String 3.10.1 , § 3.10.2 , § 3.10.3 ,
§ 3.10.4 , § 3.10.5 )
• Casts to primitive types and casts to type String 15.16 )
• The unary operators + , - , ~ , and ! (but not ++ or -- ) (§ 15.15.3 , § 15.15.4 , § 15.15.5 ,
§ 15.15.6 )
• The multiplicative operators * , / , and % 15.17 )
Search WWH ::




Custom Search