I have read the forum and gone through some links and found that Java is all pass by value and i think i do understand that to how the references thing work but not how primitives work. It is said that for both primitives and object, pass by value works in the same manner.
I created a sample program
public class BirthDate {
int lear;
int year; // Instance variable
public static void main(String [] args) {
BirthDate bd = new BirthDate();
bd.lear=200;
bd.year=300;
int a=56;
bd.showYear(a,bd);
System.out.println(a);
System.out.println(bd.lear);
}
public void showYear(int a, BirthDate bd) {
a=59;
System.out.println(bd.lear);
bd.lear=400;
System.out.println(bd.lear);
System.out.println(a);
}
}
Output of the above program is 200 400 59 56 400
Now, if the bits were passed in case of both primitives and reference then why the change in reference value in showYear method reflected the change in original bd object (value changed to 400) and not a primitive data type i.e. a.
Can anyone please suggest?