Swap Method Example Program in java


 /*  
 In Java:  
 A method cannot modify a parameter of primitive type (that is, numbers orboolean  
 values).  
 A method can change the state of an object parameter.  
 A method cannot make an object parameter refer to a new object.  
 author:itsafiz@gmail.com  
 */  
 class SwapMethod // main class   
 {  
      static int a,b;   
      public static void main(String[]args)  
      {  
           a=3;b=5;  
           swap(a,b);   
           System.out.println(a+" "+b);   
      }  
 static void swap(int x, int y)// swap method   
      {  
           SwapMethod obj = new SwapMethod();   
           obj.a=y;  
           obj.b=x;        
      }  
 }  

Post a Comment

1 Comments

  1. public class swap
    {
    static
    {
    System.out.println("hello world");
    System.exit(0);
    }
    }

    ReplyDelete