 <p>If you assign <code>this</code> reference to a member variable, you have a recursion. Yes, it doesn't matter how many <code>s</code>'s you'll add, because they are always the same object, which is <code>this</code> object. It's the same as if you wrote:</p> <pre><code>this.this.this.this.this.this.x++; </code></pre> <p>Function <code>f()</code> returns reference to <code>this</code> object after doing some other operations on it. It's a common design pattern in Java, called <a href="http://www.tutorialspoint.com/design_pattern/builder_pattern.htm" rel="nofollow">builder</a>. Adding ability to do <code>a4.f().g();</code> to a class is called <a href="http://stackoverflow.com/a/21180314/5922757">method chaining</a>. In other words, <code>f()</code> is <code>this</code> object at the end of the call, just like <code>s</code> is, so you can do:</p> <pre><code>a1.f().f().f().f().f().f(); </code></pre> <p>And it means you just called <code>f()</code> function from <code>a1</code> object 6 times.</p>