Programming Blog

This blog is about technical and programming questions and there solutions. I also cover programs that were asked in various interviews, it will help you to crack the coding round of various interviews

Friday 2 March 2018

Call By Value

                             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