We will recall two concepts 'Call by Value' and 'Call by Reference' in context of a method call.
Call By Value : when we call a method by passing any value type, a copy of value type created inside of method so, any change to the variable's value inside the method, is local to that method, it will not change value of variable passed to that method. for example :
Now, Question is about to 'Reference Type', Reference types are 'Passed by Value' or 'Passed by Reference' ?
You may not believe, if I will say reference types are also 'Passed by Value' because generally we saw when we pass any object to any method (say M1), any change to object inside M1() will reflect to caller. for example :
No, It's not correct answer, objects are also 'Passed by Value'. See below example :
No comments:
Post a Comment