title: Data hiding in java with Dynamic Variable
body: <p>I am reading Java in NutShell and came across Data Hiding. And than I tried few example and got confused in 1 of the example.</p>
  
  <p>Suppose we have this two classes:</p>
  
  <pre><code> Class Parent{
    public int a=1;
    }
  
   Class Child extends Parent {
    public int a=2;
   }
  </code></pre>
  
  <p>And Creating object of this two class in main fuction:</p>
  
  <pre><code>public static void main (String args[])
  {
      Child ch= new Child();
      Parent pa=new Child();
  
      System.out.println(ch.a);
      System.out.println(pa.a);
   }
  </code></pre>
  
  <p>And the output is: 2 and 1
  I dont understand why second line is printing 1. Since pa is the object of Child, it should be hiding the value of parent class. </p>
  
  <p>Can anyone please explain how this works?</p>