title: Why is it allowed for a parent class object to be instantiated using a child class's constructor?
body: <p>Consider the following:</p>
  
  <pre><code>public class parent {
      int x;
  
      parent() {
          x = 5;
      }
  
  }
  
  public class child extends parent {
  int y;
  
  child() {
      super();
      y = 10;
  }
  
  public static void main(String[] args) {
  
      parent p = new child();
      System.out.println(p.y);//can't access variable y
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Here a child class's constructor is being called on a parent class's object. I've come across this situation many times when doing Android programming.
      My question is why is this allowed? The child class's constructor might initialize additional members, but their blueprint might not be defined in the parent class like in the above case. </p>