title: What exactly does A a = new B() mean in java
body: <p>I get why <code>a.get()</code> returns 20, it is because of dynamic binding since object of B is created at runtime so it calls the <code>get()</code> in class B</p>
  
  <p>But why does <code>a.x</code> print 10?</p>
  
  <pre><code>class A {
    int x = 10;
  
    int get() {
       return x;
    }
  }
  
  class B extends A {
    int x = 20;
  
    int get() {
      return x;
    }
  }
  
  class Main {
    public static void main(String[] args) {
      A a = new B();
      System.out.println(a.get()); //20
      System.out.println(a.x); //10
    }
  }
  </code></pre>
  
  <p>If you could also explain the memory used in storing the object here.</p>