Saturday, 25 May 2013

Java argument and a parameter

Tags

What is the difference between an argument and a parameter?
An argument is the value or variable used to call a subroutine. A parameter is the variable defined in the subroutine’s scope bearing the value of the argument with which it was called.

How many ways can an argument be passed to a subroutine and explain them?
An argument can be passed by value or by reference. When passing by value, a copy of the argument is created and passed to the routine. When passing by reference, the argument’s reference is passed to the routine. Unless the parameter is declared final, arguments are always sent by value in Java. However, bear in mind that object variables store references to objects allocated in memory. So when passing a reference by value, you can effectively access the object stored in memory and referenced by the function argument/parameter. Final parameters cannot be changed so there’s no need to create a copy.


EmoticonEmoticon