To call swap programs into main method using third way
01/01/2002 07:49
This type of calling function into main method is called as "call by reference" method
public class reference
{
int a=10;
int b=15;
void swap(reference ob1)
{
int c;
c=ob1.a;
ob1.a=ob1.b;
ob1.b=c;
System.out.println(a);
System.out.println(b);
}
public static void main(String args[])
{
reference ob1=new reference();
ob1.swap(ob1);
}
}
Same program can be made by using "Static" keyword
public class reference
{
static int a=10;
static b=15;
static void swap()
{
int c;
c=a;
a=b;
b=c;
System.out.println(a);
System.out.println(b);
}
public static void main(String args[])
{
swap();
}
}