Call By Referance in JAVA

 public static void main ( String[] args ) {
      Number a = new Number();
      a.x=3;
      System.out.println("Value of a.x before calling increment() is "+a.x);
      increment(a);
      System.out.println("Value of a.x after calling increment() is "+a.x);
   }

   public static void increment(Number n) {
      System.out.println("Value of n.x before incrementing x is "+n.x);
      n.x=n.x+1;
      System.out.println("Value of n.x after incrementing x is "+n.x);
   }

Value of a.x before calling increment() is 3
Value of n.x before incrementing x is 3
Value of n.x after incrementing x is 4
Value of a.x after calling increment() is 4

Comments

Popular posts from this blog

தட்டு வண்டியில் காளிக்கோயில் - சிறுகதை

பிரேமாவின் பெண் குழந்தை

தீபம் பிளக்ஸ்