Embed presentation
Download to read offline


![EXAMPLE OF CALL BY VALUE IN JAVA
class Operation{
int data=50;
void change(int data)
{
data=data+100;
}
public static void main(String args[]){
Operation op=new Operation();
System.out.println("before change "+op.data);
op.change(500);
System.out.println("after change "+op.data);
}
}
Output:before change 50
after change 50](https://image.slidesharecdn.com/callbyvalueandcallbyreferenceinjava-210812090009/85/Call-by-value-and-call-by-reference-in-java-3-320.jpg)

![class Operation2
{
int data=50;
void change(Operation2 op)
{
op.data=op.data+100;//changes will be in the instan
ce variable
}
public static void main(String args[])
{
Operation2 op=new Operation2();
System.out.println("before change "+op.data);
op.change(op);//passing object
System.out.println("after change "+op.data);
}
}
Output:before change 50
after change 150](https://image.slidesharecdn.com/callbyvalueandcallbyreferenceinjava-210812090009/85/Call-by-value-and-call-by-reference-in-java-5-320.jpg)
Java uses call by value, where changes made to a parameter in a method are not reflected in the calling method. When an object is passed as a parameter, the reference value is passed by value, so changes to the object's fields will be visible in the calling method. The document provides examples of call by value using primitive types, where changes are not visible, and call by value using an object, where changes to the object's field are visible.


![EXAMPLE OF CALL BY VALUE IN JAVA
class Operation{
int data=50;
void change(int data)
{
data=data+100;
}
public static void main(String args[]){
Operation op=new Operation();
System.out.println("before change "+op.data);
op.change(500);
System.out.println("after change "+op.data);
}
}
Output:before change 50
after change 50](https://image.slidesharecdn.com/callbyvalueandcallbyreferenceinjava-210812090009/85/Call-by-value-and-call-by-reference-in-java-3-320.jpg)

![class Operation2
{
int data=50;
void change(Operation2 op)
{
op.data=op.data+100;//changes will be in the instan
ce variable
}
public static void main(String args[])
{
Operation2 op=new Operation2();
System.out.println("before change "+op.data);
op.change(op);//passing object
System.out.println("after change "+op.data);
}
}
Output:before change 50
after change 150](https://image.slidesharecdn.com/callbyvalueandcallbyreferenceinjava-210812090009/85/Call-by-value-and-call-by-reference-in-java-5-320.jpg)