An assignment statement gives a value to a variable. For example,
x = 5;
x the value 5.
The value of a variable may be changed. For example, if
the value 5, then the assignment statement
x = x + 1;
x the value 6.
The general syntax of an assignment statement is
variable = expression;
variablemust be declared;
variablemay be a simple name, or an indexed location in an array, or a field (instance variable) of an object, or a static field of a class; and
variable. In other words, it must be possible to cast the expression to the type of the variable.
int i = 0;
price[itemNumber] = 0.80 * price[itemNumber];
myDog.name = "Fido";
An assignment "statement" is not really a statement (although it is typically used that way), but is an expression. The value of the expression is the value that is assigned to the variable. For example, the expression
i = j = k = 0;
sets all of
k to zero.