Recently I faced this question the answer was kinda wiered to me
public class Q22 {
public void doIt(int x, Person y){
x=5;
y.number=8;
}
public static void main(String[] args) {
Person p = new Person();
int x = 0;
new Q22().doIt(x, p);
System.out.println(x+" , "+p.number);
}
}
class Person{
public int number;
}
Outputs : 0 , 8 instead of 5, 8
Why on the earth this happens? Could someone please explain to me with thanks.