Since Java doesnt support pointers, How is it possible to call a function by reference in Java like we do in C and C++??
You cannot do call by reference in Java. Period. Nothing even comes close. And passing a reference by value is NOT the same as call by reference.
I used an array to do this...
package method;
import java.util.Scanner;
public class InterChange {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int a[]=new int[2];
System.out.println("Enter two values");
for(int i=0;i<2;i++) {
a[i]=sc.nextInt();
}
hange(a);
for(int i=0;i<2;i++) {
System.out.println(a[i]);
}
}
static int hange(int b[])
{
int temp;
temp=b[0];
b[0]=b[1];
b[1]=temp;
return b[0]&b[1];
}
}