Call by value Example using java programming code
public class CallByValue {
public static void swap(int a, int b) {
// Swap
int temp = b;
b = a;
a = 35;
}
public static void main(String[] args) {
// swap - value exchange
int a = 45;
int b = 25;
swap(a, b);
System.out.println("a is : " + a);
System.out.println("b is : " + b);
}
}
No comments:
Post a Comment