How Java pass parameters to method ? Call by Reference or Call by Value ?
One of the tricky parts of java to understand, whether it support call by value or call by reference while using methods. Java supports both of them based on the type of the passed parameter. Let's dive into that.
Call By Value and Call By Reference :
There are two ways to pass an argument to a method
One of the tricky parts of java to understand, whether it support call by value or call by reference while using methods. Java supports both of them based on the type of the passed parameter. Let's dive into that.
Call By Value and Call By Reference :
There are two ways to pass an argument to a method
- call-by-value : In this approach copy of an argument value is pass to a method. Changes made to the argument value inside the method will have no effect on the arguments.
- call-by-reference : In this reference of an argument is pass to a method. Any changes made inside the method will affect the agrument value.
Here is the point to remember : In Java, when you pass a primitive type to a method it is passed by value whereas when you pass an object of any type to a method it is passed as reference.
That's it Happy Learning!!!!!!
No comments:
Post a Comment