website counters

Thursday, October 6, 2016

Swapping(Call by reference)

/*Swapping-call by reference */

class Swappingref{

    int x,y;

    Swappingref(int x,int y){
        this.x=x;
        this.y=y;
    }

    void swapping(Swappingref obj){

        int temp=obj.x;
        obj.x=obj.y;
        obj.y=temp;
    }

    public static void main(String[]args){

        Swappingref object=new Swappingref(5,6);

        object.swapping(object);

        System.out.println("After swap:\n"+"X:"+object.x+"           Y:"+object.y);
    }
}

No comments:

Post a Comment