title: java array of objects and inheritance
body: <p>I have 3 classes, MainClass with main method, one abstract class named AbstractClass and Subclass which is to be extended with AbstractClass.</p>
  
  <p>The array of objects is created in main method from type AbstractClass containing 1 member.
  Then I initialize that 1 element of array as type  Subclass( is this ok?).
  The problem is I can't get to the getDataToExport() method of created object ( array[0] ) .
  I suspect the problem occurs because the array is the AbstractClass type...
  And the question:  is this even possible to accomplish?
  What I'm trying to do is use an array of type AbstractClass and fill it with objects made from different subclasses( in this code is just one->Subclass ) extended with AbstractClass but i can't get to the methods of that subclasses.</p>
  
  <p>main class with main method </p>
  
  <pre><code>public class MainClass {
  
      public static void main() {
  
          AbstractClass array[]=new AbstractClass[1];
          array[0]= new Subclass(); // is this even allowed?
          System.out.println(array[0].getDataToExport()); // Problem!
  
      }
  
  }
  </code></pre>
  
  <p>abstract class  </p>
  
  <pre><code>public abstract class AbstractClass {
  
  }
  </code></pre>
  
  <p>Subclass which extends AbstractClass</p>
  
  <pre><code>public class Subclass extends AbstractClass {
  
      private int dataToExport;
  
      public Subclass(){
          this.dataToExport=2;
      }
  
      public int getDataToExport() {
          return dataToExport;
      }   
  
  }
  </code></pre>