Advertisement
AnindyaBiswas

call

Jun 1st, 2022
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class call {
  3.  
  4.     static void call_by_value(int a, int b)
  5.     {
  6.         int c = a;
  7.         a = b;
  8.         b = c;
  9.         System.out.println("In call_by_value\na = " + a + " b = " + b);
  10.     }
  11.  
  12.     static void call_by_ref(int ar, Integer br)
  13.     {
  14.         int a = ar, b = br, c;
  15.         ar = br;
  16.         c = a;
  17.         a = b;
  18.         b = c;
  19.         System.out.println("In call_by_ref\na = " + a + " b = " + b);
  20.     }
  21.  
  22.     public static void main(String[] args)
  23.     {
  24.         int a = 10, b = 20;
  25.         System.out.println("In Main\na = " + a + " b = " + b);
  26.         Integer a_ref = new Integer(10);
  27.         Integer b_ref = new Integer(20);
  28.         call_by_value(a, b);
  29.         call_by_ref(a_ref, b_ref);
  30.         System.out.println("Again, in Main\na = " + a_ref + " b = " + b_ref);
  31.  
  32.     }
  33.    
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement