Consider the following method definition:
public static String duplicate(String pf) { return pf + ", " + pf; }
Consider then the following main method:
public static void main(String[] args) { String s; s = duplicate("pippo" + "&" + "topolino"); System.out.println(s); }
Let us analyze in detail what happens when the statement containing the call to the duplicate method is executed:
In our case, the actual parameter is the expression "pippo" + "&" + "topolino" whose value is the string "pippo&topolino".
In our case, the method we are looking for must have the signature duplicate(String).
In our case, it is the method main.
In our case, memory is allocated for the formal parameter pf.
In our case, the formal parameter pf is initialized to the reference to the object representing the string "pippo&topolino".
In our case, the statement return pf + ", " + pf; is executed.
In our case, the memory location corresponding to the formal parameter pf is freed.
In our case, the result is "pippo&topolino, pippo&topolino".
In our case, the value "pippo&topolino, pippo&topolino" is assigned to the variable s.