It looks perfectly fine to me.
A good way to treat variables in Java is as a pointer or address.
this.rest = new Stack1(this);
Before executing this line, this.rest
points to something (could be an object or null, doesn't matter). An analogy would be if you had an address to a house on a piece of paper (say your friend Bob's house).
In the constructor of the new Stack1 object, it's copying that address but not the object. This could be viewed as your friend Gary copying the address you have written down for Bob. Now if you both go to the same address, you'll find the same house and if you decide to paint the walls yellow, you're friend will see that Bob has yellow walls.
However, back in the push method, you modify your this.rest
. This is analogous to you changing the address you have written down to the address of Gary's house. It has no effect on the address your friend Gary has written down, which still points to Bob's house. Now if you go and modify Gary's house, the changes won't be visible at Bob's house.
It is interesting to note, that by going to Gary's house you can still find Bob's house. Since Gary has Bob's address written down and you know where Gary lives, you just go to Gary's house and ask him. The java code would be this.rest.rest
(assuming you're at the end of the push method).