Next: Static methods
Up: Unit 02
Previous: Evaluation of the expression
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
"yyy".concat("zzz")
- "yyy" denotes the invocation object
- "zzz" denotes the parameter
- both are directly available, hence we can compute
"yyy".concat("zzz"), which returns the string "yyyzzz"
- After having evaluated "yyy".concat("zzz"), we can continue with
"xxx".concat(...)
- "xxx" denotes the invocation object
- "yyyzzz" denotes the parameter computed at item 1
- both are now available, hence we can compute
"xxx".concat("yyyzzz"), which returns the string
"xxxyyyzzz"
Hence, the statement
System.out.println("xxx".concat("yyy".concat("zzz"))); prints
"xxxyyyzzz".
The evaluation of the expressions denoting the parameters is done from the
inside to the outside, computing each time the parameters of each call before
the call is evaluated.
Next: Static methods
Up: Unit 02
Previous: Evaluation of the expression