Thursday, December 20, 2007

Pass by value in java not by reference

package gc;

public class Swap
{
int i=10;
String s="hello";
String t="world";
public static void swap(Swap integer)
{
String temp = integer.s;
integer.s=integer.t;
integer.t=temp;
}
public static void main(String[] args){


Swap integer=new Swap();
swap(integer);
add(integer);
System.out.println(integer.i);
System.out.println(integer.s+"=="+integer.t);

}

public static void add(Swap integer)
{
//MInteger integer1=new MInteger();
integer.i=0;;
}

}

0 comments: