There is only call by value in java, not call by footnote. If we call a way(method) passing a
value, it is known as call by value. The changes being done in the called way(method) , is not
affected in the calling way(method) .
Example of call by value in java
In case of call by value real value is not changed. Let’s take a simple example:
class Operation{
int data=50;
void change(int data){
data=data+100;//changes will be in the local variable only
}
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
In Java, parameters are alway(method) s passed by value. For example, following
program printsi = 10, j = 20.
// Test.java
class vish {
// swap() doesn’t swap i and j
public static void swap(Integer i, Integer j) {
Integer temp = new Integer(i);
i = j;
j = temp;
}
public static void main(String[] args) {
Integer i = new Integer(10);
Integer j = new Integer(20);
swap(i, j);
System.out.println(“i = ” + i + “, j = ” + j);
}}