Hello,
Passing by value means "passing by copying the value." So when you pass an object you pass a copy of the reference, and if that reference is changed that does not impact the reference of the calling code (the new reference exists in the method body).
By cons, if the object is changed, so there it works:
Code:
void exchange(StringBuffer strbuf)
{
strbuf.delete(0Sb.length()); / / We erase all
strbuf.append(Goodbye);
}
And see this code
Code:
StringBuffer mstr = New StringBuffer("Hello");
exchange(mstr);
System.out.println(mstr);
Bookmarks