title: How is the 'this' variable in Java actually set to the current object?
body: <p>Consider:</p>
  
  <pre><code>class TestParent{
    public int i = 100;
    public void printName(){
      System.err.println(this); //{TestChild@428} according to the Debugger.
      System.err.println(this.i); //this.i is 100.
    }
  }
  
  class TestChild extends TestParent{
    public int i = 200;
  }
  
  public class ThisTest {
    public static void main(String[] args) {
      new TestChild().printName();
    }
  }
  </code></pre>
  
  <p>I know that similar questions have been asked, but I couldn't get a firm understanding of the 'this' variable in Java.</p>
  
  <p>Let me try to explain how I understand the result of the above image.</p>
  
  <ol>
  <li><p>Since it's a <code>new TestChild()</code> object that's calling the <code>printName()</code> method, the <code>this</code> variable in line 6 is set to a <code>TestChild</code> object - {TestChild@428} according to the Debugger.</p></li>
  <li><p>However, since Java doesn't have a virtual field - I'm not completely sure what this means, but I conceptually understand it as being the opposite of Java methods, which support Polymorphism - <code>this.i</code> is set to 100 of <code>TestParent</code> at compile time.</p></li>
  <li><p>So no matter what <code>this</code> is, <code>this.i</code> in a <code>TestParent</code> method will always be the <code>i</code> variable in the <code>TestParent</code> class.</p></li>
  </ol>
  
  <p>I'm not sure that my understanding is correct so please correct me if I'm wrong.</p>
  
  <p>And also, my main question is,</p>
  
  <p>How is the <code>this</code> variable set to the current object that's calling the method? How is it actually implemented?</p>