title: Why this is happening in Java?
body: <p>I have been knowing java for a while still sometime i think, i lack few basic concepts. Here is a code which i am trying to run:</p>
  
  <pre><code>   class A{
      int x =10;
      void al(){
          System.out.println("From a");
      }
  }
  class B extends A{
      int x = 20;
      void al(){
          System.out.println("From b");
      }
  
      public static void main(String args[]){
          A obj = new B();
          B obj1 = new B();
          A obj2 = new A();
          System.out.println(obj.x);
          obj.al();
          System.out.println(obj1.x);
          System.out.println(obj2.x);
      }
  }
  </code></pre>
  
  <p>and here is the output:</p>
  
  <pre><code>  10
  From b
  20
  10
  </code></pre>
  
  <p>When i try to call the function <strong>al</strong> it calles the function in <strong>B</strong> class. Simple overriding is happening over here. Obj tries to find first in base class then in super class.
  Now, when i try to access the "X" by object <strong>obj</strong> it displays "10".
  Why it is not displaying "20" ?  </p>