title: Parent class reference pointing to Child class Object
body: <p>I have confusion in object life cycle. If parent class reference pointing to the child class object and method is overridden. For example </p>
  
  <pre><code>class Parent {
       public void display(){
             System.out.println("i am from Parent");
       }
  }
  
  class Child extends Parent {
       public void method1() { }
  
       public void display(){
             System.out.println("i am from Child class");
       }
  }
  </code></pre>
  
  <p>Now if I create the in main class</p>
  
  <pre><code>Parent p = new Child();
  </code></pre>
  
  <p>Is my understanding object life cycle is proper or not? If not please guide me.</p>
  
  <ol>
  <li><p>new <code>Child()</code> constructor get called</p></li>
  <li><p>by <code>super()</code> method parent class constructor(default constructor) get called</p></li>
  <li><p>now according to object life cycle first constructor get called and concrete method that is <code>display()</code> method from parent class get stored in heap.</p></li>
  <li><p>after Child class constructor finish the execution and <code>method1()</code> and <code>display()</code> method get stored in heap memory.</p></li>
  </ol>
  
  <p>Now if I call <code>p.display()</code> its going to execute child class <code>display()</code> method, but if you see both parent and child class <code>display()</code> method stored in heap memory.</p>
  
  <p>If this behavior proper then what is the use of storing the <code>display()</code> method of parent in heap. </p>