title: Getting data from children classes: Java
body: <p>I'm new here, so I apologize in advance if I do not follow standard etiquette on accident.</p>
  
  <p>I'm wondering how to get data from a child class, using ArrayLists.</p>
  
  <pre><code>import java.io.*;
  import java.util.*;
  
  public class MyProgrammingLab {
  
      public static void main(String[] args){
          ArrayList&lt;Test&gt; testArray = new ArrayList&lt;&gt;();
  
          testArray.add(new Test("First"));
          testArray.add(new SubTest("Last"));
  
          System.out.println(testArray.get(0).getFirstName());
          System.out.println(testArray.get(1).getLastName());
      }
  }
  
  public class Test {
      private String firstName;
  
      public Test(){
      }
  
      public Test(String firstName){
          this.firstName = firstName;
      }
  
      public String getFirstName() {
          return firstName;
      }
  }
  
  public class SubTest extends Test{
      private String lastName;
  
      public SubTest(){
          super();
      }
  
      public SubTest(String lastName){
          this.lastName = lastName;
      }
  
  
      public String getLastName(){
          return lastName;
      }
  }
  </code></pre>
  
  <p>The line in my main "System.out.println(test.Array.get(1).getLastName());" is throwing errors at me, and I can't figure out why? </p>
  
  <p>In my main program, I'll be using an ArrayList of size greater than 1.</p>
  
  <p>Thank you in advance!</p>