Java assignment operator

Introduction

The assignment operator is the single equal sign =.

It has this general form:

variableName = expression; 

Here, the type of variableName must be compatible with the type of expression.

The assignment operator can create a chain of assignments.

For example, consider this fragment:

int x, y, z;  
         
x = y = z = 100; // set x, y, and z to 100 

This fragment sets the variables x, y, and z to 100 using a single statement.

The = is an operator that yields the value of the right-hand expression.

The value of z = 100 is 100, which is then assigned to y.




PreviousNext

Related