weare creating a new object. It will have a different memory address than the one passed with setString(string1);

We would need to change the object received at

private void setString(StringBuilder s) { ... }

instead of creating a new one. We need to use exactly the same object we were passed in this method. Can't create a new one, as the caller method wouldn't notice (parameters in Java are never output parameters).

As Java's String is inmutable, we can't change its content: just create a new String object.

As @adarshr pointed out, we can use StringBuilder or StringBuffer, which are mutable, and change their content. But we can't just replace String with StringBuilderin you code. We have to make sure that:

The StringBuilder is initialized before being passed to setString().

The StringBuilder is not created again inside setString() (we are using the same one we were passed).

ur application is assigning the hello word in parameter s..but the variable s is a parameter type thats y the reflection of s will be in setString() method block...not anywhere else...use instance variable or static variable to see the reflection of ur assignment.