When you write
DumObj one = new DumObj();
it's important to realise that one
is not a DumObj
- it's a reference to DumObj
, and references are passed by value.
So you're always passing by value, and you can change the passed reference (so your passed reference now points to a different object). However, your object itself could be mutable, so this:
one.setValue(123);
will change the referenced object. When you call this:
public void setToNull(DumObj two)
{
two = null;
}
you're changing the passed reference (remember - it's been passed by value and is local to the method!) and so your original object and original reference are not affected.