Variable binding and keyword this in Java
<p>In the following code how does the variable x in the method getX() get bound to the member field of instance of Class A even when at runtime 'this' refers to an object of type B. Does this happen at compile time or at run time. </p>

<pre><code>class A {

    public void getX(){
        Class cls = this.getClass();  
        System.out.println("The type of the object is: " + cls.getName());
        System.out.format("value of x = %d\n", this.x);}

    public int x = 0;
}

public class B extends A {

    public static void main(String[] args) {
        B obj = new B();
        obj.getX();}

    public int x = 1;
}
</code></pre>

<p>the output  is:</p>

<pre><code>The type of the object is: B
value of x = 0
</code></pre>
