G
getsanjay.sharma
Hello friends, I am facing a lot of confusion over a simple issue of
parameter passing. Just let me know what I have figured out is right
or wrong:
"There is no pass by reference in Java. Everything is passed by value.
In case of primitive types, a copy of the variable which holds its
value is made and passed to the called function. In case of objects, a
copy of the reference is made and passed to the called function. It is
this reference variable which holds the actual reference to an object.
Think of the reference variable as a container which holds a remote
control, the remote being the object reference. When a reference
variable is passed, this remote is passed by value hence the called
function can manipulate the passed object. An exception here is the
objects of class String since Strings in Java are immutable."
Looks good? Any interesting links would be appreciated.
parameter passing. Just let me know what I have figured out is right
or wrong:
"There is no pass by reference in Java. Everything is passed by value.
In case of primitive types, a copy of the variable which holds its
value is made and passed to the called function. In case of objects, a
copy of the reference is made and passed to the called function. It is
this reference variable which holds the actual reference to an object.
Think of the reference variable as a container which holds a remote
control, the remote being the object reference. When a reference
variable is passed, this remote is passed by value hence the called
function can manipulate the passed object. An exception here is the
objects of class String since Strings in Java are immutable."
Looks good? Any interesting links would be appreciated.