title: overriding a variable in java
body: <pre><code>public class Foo {
        public int a = 3;
      public void addFive(){
          a += 5; System.out.print("f ");
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>public class Bar extends Foo {
      public int a = 8;
      public void addFive(){ 
          this.a += 5; 
          System.out.print("b " ); 
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>public class Test {
      public static void main(String args[]){
          Foo f = new Bar(); 
          f.addFive();
          System.out.println(f.a);
      }
   }
  </code></pre>
  
  <p>I am getting output b 3 .why it is not giving b13 as output.Can anyone please explain.</p>