Next: Evaluation of the expressions
Up: Unit 02
Previous: Evaluation of 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.
- It is possible to evaluate immediately the subexpression
"xxx".concat("yyy")
- "xxx" denotes the invocation object
- "yyy" denotes the parameter
- both are directly available, hence we can compute
"xxx".concat("yyy"), which returns the string "xxxyyy"
- After having evaluated "xxx".concat("yyy"), we can continue
with concat("zzz")
- "xxxyyy" denotes the invocation object
- "zzz" denotes the parameter
- both are now available, hence we can compute
"xxxyyy".concat("zzz"), which returns the string
"xxxyyyzzz"
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: Evaluation of the expressions
Up: Unit 02
Previous: Evaluation of a method