in this code
Why this prints >> 0 8 instead of >> 5 8 .
The method doIt()
changes the number of Person p which is already allocated, but the int x is already allocated and is not changed in doIt()
.
Can anyone give me an theoretic explanation? I'm trying to understand how it works.
Thanks.
class Person{
int number=0;
}
class Student extends Person
{
int studentNumber;
}
public class Prog{
public void doIt(int x, Person p)
{
x=5;
p.number=8;
}
public static void main(String[] args) {
Prog p = new Prog();
p.test();
}
public void test()
{
int x=0;
Person p = new Person();
doIt(x,p);
System.out.println(x);
System.out.println(p.number);
}
}