There are two variables, p and q, initially containing null.
After execution of these assignments:
p= new Animal();
q= new Patient();
p= new Animal();
the variables and created objects look like this:
There are two variables, p and q, initially containing null.
After execution of these assignments:
p= new Animal();
q= new Patient();
p= new Animal();
the variables and created objects look like this: