If you change the details of p
as such, it'll get reflected
// Nothing done to p before this
p.changeName("Not Sanika Anymore"); // This will be reflected as both point to the same object as references are the same
If you create a new Person and assign it to p
then it wont
// New Person for p
p = new Person("New Sanika"); // now this p is pointing to the newly created object's reference
p.changeName("Not Sanika Anymore"); // This won't be reflected
That is because java is purely pass-by-value. You are passing the reference of the object as a value to callFunction()
.
This answer by Eng.Fouad explains this concept in a really good way.