Ok so if primitive data types in java are passed into methods, they are treated as pass by value. And if object data types are passed into methods, they are treated as pass by reference right? So in this code:
//Class 1
public void passByValue(int x){
x = 0;
}
public void passByReference(Integer y){
y= 40;
}
//MainClass(contains main method)
int primitiveType = 50;
Integer wholeInteger = 100;
Class1 a = new Class1();
a.passByValue(primitiveType);
a.passByReference(wholeInteger);
System.out.println(primitiveType);
System.out.println(wholeInteger);
This should result in primitiveType being equal to 50(variable hasnt changed). I understand that, however the Integer object is also not changed... So how does this work? Thanks!