An expression statement simply evaluates an expression.
An expression statement is just the expression followed by a semicolon (
No all expressions can be treated as statements in this way. For example:
is not a legal expression statement. Since no side-effects result from
String literal and then discarding it, the statement is
useless. Only the following expressions may be used as statements:
- assignment or compound assignment,
- prefix or postfix increment or decrement,
- invocation of a method, or
- instantiation of a class.
On execution, the expression's value is discarded.