How and when is a Remote object replaced by its stub?
In general, remote objects are not replaced by their stubs. The remote object remains on the server and the stub is delivered to the client to act as a proxy for accessing the remote object. The common bond between the stub and the remote object is the remote interface that they both implement which allows a stub on a client machine to operate as if it was the remote object on the client.
There is one place where a remote object is actually replaced by a stub. If a remote object that has been exported is passed as a parameter to, or returned as the result from, a remote method call, then the remote object is replaced by its stub. So for instance, if a remote object returns itself (i.e. this) from a remote method, then instead of marshalling the remote object and passing it to the caller a stub for the remote object is returned.