Difference between call by value and call by reference

package multiconstructor;
import java.util.Scanner;
public class Multiconstructor {
public Multiconstructor(int args1, int args2)   //constructor having same class name and a return type
{
System.out.println("Sum of two no by call by reference " + (args1 + args2));
}
void call_by_value(int a, int b) {
int c = a + b;
System.out.println("Sum of two no by call by value " + c);
}
public static void main(String args[]) {
Scanner define = new Scanner(System.in);
System.out.println("integer parameter");
int s1 = define.nextInt();
int s2 = define.nextInt();
Multiconstructor m1 = new Multiconstructor(s1, s2);             // constuuctor calling so call by    reference
m1.call_by_value(s1, s2); // method calling so call by value
}
}


OUTPUT 
3
4
Sum of two no by call by reference 7
Sum of two no by call by value 7

No comments:

Post a Comment