Code: Select all
public class TestClass {
public static void main(String args[ ] ) {
int i = 1;
int[] iArr = {1};
incr(i) ;
incr(iArr) ;
System.out.println( "i = " + i + " iArr[0] = " + iArr [ 0 ] ) ;
}
public static void incr(int n ) { n++ ; }
public static void incr(int[ ] n ) { n [0]++ ; }
}
why int i is unchanged but int[] iArr is changed?
iArr [0] should have a default value of 0, how did it get to 2?
is there anything to do with the static keyword in the methods?