Java When outputting String and method return, why does method return output first?

后端 未结 5 1042
Happy的楠姐
Happy的楠姐 2021-01-23 06:03

In the code below, if the string \"Mult\" comes before the test1(4) method call, why does the method output before the string? And why does it bounce f

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-23 06:34

    "Mult:" + test1(4)
    

    The above line is an expression whose value is the concatenation of "Mult:", and of the result of test1(4). So, to be able to know the result of this concatenation, test1(4) is executed. This execution prints "N:4", and then multiplies n by 2, returning 8. 8 is then concatenated with "Mult:", and the result is printed.

提交回复
热议问题