I realize this is a commonly asked question, but here it is ..
I tried to write this to figure out how Java handles parameter passing and so on..
public class CallByValue {
int key;
public void changeValue(CallByValue c){
System.out.println(c);
c.key=7;
}
public void changeValue(int x){
x=0;
}
public static void main(String[] args){
CallByValue c=new CallByValue();
c.key=5;
System.out.println(c);
c.changeValue(c);
System.out.println(c.key);
int x=8;
c.changeValue(x);
System.out.println(x);
}
}
Here I can change the value of a primitive inside an object passed to a method, but I cannot change the value of a primitive passed into a method. Is there a reason why.