Call By Value In Java
If we call a method passing a value, it is known as call by value. The changes being done in the called method is not affected by the calling method.
Example
Here I will show you an example of call By Value in JAVA.
In case of call by value original parameters are not changed, the changes made are local to the function in which they are defined.
class CallByValue{
int data=10;
void change(int data){
data=data+100; /*changes will be in the local variable only*/
}
public static void main(String args[]){
CallByValue op=new CallByValue();
System.out.println("before change "+op.data);
op.change(50);
System.out.println("after change "+op.data);
}
}
No comments:
Post a Comment