September 2011
Beginner
650 pages
15h 47m
English
You have been using the assignment operator since Chapter 1. Now it is time to take a formal look at it. The assignment operator is the single equal sign, =. This operator works in Java much as it does in any other computer language. It has this general form:
var = expression;
Here, the type of var must be compatible with the type of expression.
The assignment operator does have one interesting attribute that you may not be familiar with: it allows you to create a chain of assignments. For example, consider this fragment:

This fragment sets the variables x, y, and z to 100 using a single statement. This works because the ...
Read now
Unlock full access