Call-by-value: This method copies the value of an argument into the formal parameter of the subroutine. Therefore, changes made to the parameter of the subroutine have no effect on the argument.
Call-by-reference: In this method, a reference to an argument (not the value of the argument) is passed to the parameter. Inside the subroutine, this reference is used to access the actual argument specified in the call. This means that changes made to the parameter will affect the argument used to call the subroutine.
When a simple type is passed to a method, it is done by use of call-by-value. Objects are passed by use of call-by-reference.
No comments:
Post a Comment