title: Java inheritance overriding instance variable
body: <p>I am learning java. I have a doubt in inheritance. When a child class extends parent class and  parent class has a method which refers to a instance variable declared in parent. But the child class dint override this method and has declared instance variable with same name as the parent. In this case instance variable from child will be referred or parent will be referred. Below is the code snippet</p>
  <pre><code>class Parent {
      int a;
      Parent() {
          System.out.println(&quot;in Parent&quot;);
          a = 10;
      }
      void method() {
          System.out.println(a);
      }
  }
  class Child extends Parent {
      int a;
      Child() {
          System.out.println(&quot;in Child&quot;);
          a = 11;
      }
  }
  
  public class Test {
      public static void main(String args[]) throws IOException {
          Parent p1 = new Child();
          p1.method();
      }
  }
  </code></pre>
  <p>The output I get is</p>
  <p>in parent <br/>
  in child <br/>
  10 <br/></p>
  <p>Can someone please make me understand why its referring parent class's instance variable <code>a</code> and not child class's <code>a</code>.</p>
  <p>Another  doubt is, I understood hiding the method, when there is a static method in parent and child class also has declared a static method with same signature. Here hiding means ? what method is getting hidden ? If its the parent method can you please explain me ? <br/>
  Thanks in advance.</p>