title: Why is an instance variable of the superclass not overridden by a subclass?
body: <p>See my code below, in which the method <code>print</code> is overridden but variable <code>a</code> is not. Why is it allowed to declare duplicate variables in a subclass?</p>
  
  <pre><code>class B {
      int a = 10;
      public void print() {
          System.out.println("inside B superclass");
      }
  }
  
  class C extends B {
      int a = 20;
      public void print() {
          System.out.println("inside C subclass");
      }
  }
  
  public class A {
      public static void main(String[] args) {
          B b = new C();
          b.print(); // prints: inside C subclass
          System.out.println(b.a); // prints superclass variable value 10
      }
  }
  </code></pre>