title: Java : Super class array object assigned with sub class array object
body: <p>I'm trying to assign a sub class object array to its super class. The program compiles successfully, but I' getting an <code>ArrayStoreException</code>. I know that arrays parent and child are references to same array, but shouldn't I be able to access method <code>func</code> at least?</p>
  
  <pre><code>class Pclass
  {
      Pclass()
      {
          System.out.println("constructor : Parent class");
      }
  
      public void func()
      { 
          System.out.println("Parent class");
      }
  }
  
  class Cclass extends Pclass
  {
      Cclass()
      { 
          System.out.println("Constructor : Child class");
      }
  
      public void func2()
      {  
          System.out.println("It worked");
      }
  
      public void func()
      { 
          System.out.println("Common");
      }
  }
  
  public class test
  {     
      public static void main(String ab[])
      {    
          Cclass[] child = new Cclass[10];
          Pclass[] parent = child;
          parent[0]=new Pclass();
          parent[0].func();
      }
  }
  </code></pre>