Tuesday, October 25, 2011

Do we need to pass a reference type argument to a method using REF keyword? - Part 02

Consider the following reference type variable x:
ArrayList x = new ArrayList()

Here, assume memory location of x is 2110 and it points to the memory location of the new object which can be 1110.

So, if you pass x variable to a method by reference without giving REF keyword, a copy of the reference, which resides in memory location 3110 is passed to the method with the value of 1110 which points to the same object.

But if you pass x variable to a method with REF keyword the original reference itself will be copied which in this case 2110.

For more info: when we should use REF keyword? - Part 01

No comments:

Post a Comment