package myintergertest;
/**
*
* @author Engineering
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void
public class passByReferenceExample {
static void incrementIt(Long b[]){
Long c = b[0];
c=c+1;
b[0]=c;
}
public static void main(String[] args) {
Long a[]={1L};
System.out.println("Before calling IncrementIt() : " + a[0]);
System.out.println();
incrementIt(a);
System.out.println("after first call to incrementIt() : " + a[0]);
incrementIt(a);
System.out.println("after second call to incrementIt(): "+ a[0]);
incrementIt(a);
System.out.println("after third call to incrementIt() : "+ a[0]);
incrementIt(a);
System.out.println("after fourth call to incrementIt(): "+ a[0]);
}
}
output:
Before calling IncrementIt() : 1
after first call to incrementIt() : 2
after second call to incrementIt(): 3
after third call to incrementIt() : 4
after fourth call to incrementIt(): 5