Java uses pass-by-value. So, when passing a reference variable, you are passing the value of the reference to the object.
The name parameter of the speak() method receives the copy of the reference, so it points to the same String as the variable name inside the main() method.
Now, remember, Strings are immutable, so you can't change the object's value.
Inside your method speak(), you are assigning a new String to your parameter called name, so it will just point to a different String. The name variable inside the main method still points to "Webby".
Thus, the caller is not affected.
Prathyu Krishna wrote:2. totally confused what reference variables are?
A reference variable is a variable that contains a reference to an object in the memory (so, the variable holds/points to an object in the memory, or points to null).
For example, assume that you have a class called Car, we can declare a reference variable of it:
Prathyu Krishna wrote:1. Strings are immutable then why does it append "d" ?
Be careful, you are not appending "d" to your String. You are doing a concatenation, which in this case creates a new String (as Roel already explained).
Your method letters() is returning the new String created by the concatenation.
As you see, you are not appending, you are doing a String concatenation, creating a new String, which means that you are not changing the original object (since Strings are immutable).
And be careful with variables and methods names. Search about good practice when naming variables and methods (like not using the same name of a variable to a method)