next up previous
Next: Evaluation of the expressions Up: Unit 02 Previous: Evaluation of a method

Evaluation of the expression denoting the invocation object for a method

What does the following statement print?

System.out.println("xxx".concat("yyy").concat("zzz"));

To provide an answer, we have to understand how the expression "xxx".concat("yyy").concat("zzz") is evaluated.

  1. It is possible to evaluate immediately the subexpression "xxx".concat("yyy")

  2. After having evaluated "xxx".concat("yyy"), we can continue with concat("zzz")

Hence, the statement System.out.println("xxx".concat("yyy").concat("zzz")); prints "xxxyyyzzz".

The evaluation of the expression that denotes the invocation object is done from left to right, by computing the invocation objects and calling on them the methods that still need to be evaluated.


next up previous
Next: Evaluation of the expressions Up: Unit 02 Previous: Evaluation of a method