title: Polymorphism inside constructors in Java
body: <h2>Code:</h2>
  
  <pre><code>class A{
  
      A()  {
          test();
      }
      void test(){
          System.out.println("from A");
      }
  }
  
  class B extends A {
  
      void test() {
  
          System.out.println("from B");
  
      }
  
  }
  
  class C {
  
      public static void main(String args []){
  
          A a = new B();
  
          a.test();
      }
  }
  </code></pre>
  
  <h2>Output:</h2>
  
  <pre><code>from B 
  from B
  </code></pre>
  
  <p>Why is it getting printed that way ?</p>