title: Polymorphism and overriding confusion
body: <p>Recently My teacher was teaching Polymorphism and he taught that there are two aspects in Polymorphism as</p>
  
  <ol>
  <li><p>Run-time Polymorphism</p></li>
  <li><p>Compile-time Polymorphism</p></li>
  </ol>
  
  <p>And then He showed us this code</p>
  
  <pre><code>class A {
      void ab(){
          System.out.println("ab() in class A");
      }
  }
  
  class B extends A {
      void ab(){
          System.out.println("ab() in class B");
      }
  }
  
  class ObCo {
      public static void main(String args[]){
          A a1 = new B();
          a1.ab();
      }
  }
  </code></pre>
  
  <p>The output is <code>ab() in class B</code></p>
  
  <p>And when I try the following code,</p>
  
  <pre><code>class A {
      int i = 10;
  }
  
  class B extends A {
      int i = 100;
  }
  
  class ObCo {
      public static void main(String args[]){
          A a1 = new B();
          System.out.println(a1.i);
      }
  }
  </code></pre>
  
  <p>According to the previous code, the output should be <code>100</code> But the output is <code>10</code> Which rises up these questions in my mind.</p>
  
  <ol>
  <li>Is Polymorphism a concept only related to Overriding methods?</li>
  <li>Is the first code block relevant to Polymorphism? </li>
  <li>If yes, what is run-time Polymorphism and compile-time Polymorphism?</li>
  <li>If no, please give me an example where Polymorphism is seen.</li>
  </ol>
  
  <p>Detailed answers on those questions will be highly appreciated.</p>