title: Null values when printing out arrayList?
body: <p>Hi I have created a toStringmethod in one of my classes which can be seen below.
  Student Class:</p>
  
  <pre><code>package Practical5;
  
  public class Student extends Person {
  
      //instance variables
      private static int MAX_MODULES = 6;
      private StudentMode modeOfStudy;
      private boolean studentLoan;
      private int numEnrolledModules;
  
      //constructor
      public Student(String name, String dob, Address address, StudentMode modeOfStudy, boolean studentLoan) {
          super(name, dob, address);
      this.modeOfStudy = modeOfStudy;
      this.studentLoan = studentLoan;
      this.numEnrolledModules = 0;
      }
  
      //accessors &amp; mutators
      public StudentMode getMode() {
          return modeOfStudy;
      }
  
      public boolean isStudentLoan() {
          return studentLoan;
      }
  
      public int getNumEnrolledModules() {
          return numEnrolledModules;
      }
  
      public void setMode(StudentMode modeOfStudy) {
          this.modeOfStudy = modeOfStudy;
      }
  
      public void setStudentLoan(boolean studentLoan) {
          this.studentLoan = studentLoan;
      }
  
      public void setNumEnrolledModules(int numEnrolledModules) {
          this.numEnrolledModules = numEnrolledModules;
      }
  
      @Override
      public void purchaseParkingPass() {
          System.out.println(getName() + " just purchased a parking pass with student discount.");
      }
  
      @Override
      public void addModule(String moduleCode) {
          if (getNumEnrolledModules() &lt; MAX_MODULES) {
              System.out.println(getName() + " successfully registered for the module: " + moduleCode);
          }
          else {
              System.out.println("You are unable to register for " + moduleCode + " as the maximum number of permitted module enrolments has been reached.");
          }
  
      }
  
      public String toString() {
          return "Student [ ID: " + getId() + "; Name: " + getName() + 
                  "; DOB: " + getDob() + "; Study Mode: " + getMode() +
                  "; Number of Enrolled Modules: " + getNumEnrolledModules();
      }
  }
  </code></pre>
  
  <p>Person Class:</p>
  
  <pre><code>package Practical5;
  
  public abstract class Person {
  
  
      //instance variables
      private static int LAST_ID = 1000 + 1;
      private int id;
      private String name;
      private String dob;
      private Address address;
  
      //constructor
      public Person(String name, String dob, Address address) {
          super();
          LAST_ID ++;
          this.id = LAST_ID;
  
      }
  
      //accessors &amp; mutators
      public int getId() {
          return id;
      }
  
      public String getName() {
          return name;
      }
  
      public String getDob() {
          return dob;
      }
  
      public Address getAddress() {
          return address;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public void setDob(String dob) {
          this.dob = dob;
      }
  
      public void setAddress(Address address) {
          this.address = address;
      }
  
      //methods
      public abstract void purchaseParkingPass();
      public abstract void addModule(String moduleCode);
  
  
  
  }
  </code></pre>
  
  <p>I then created a tester class and created a new ArrayList and added these elements to it. </p>
  
  <p>I then created a for loop in order to loop through each element and call the toString method to print out the details of each element but it is returning null values. </p>
  
  <p>Tester Class:
      package Practical5;</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.Scanner;
  
  
  
  public class UIS_Tester {
  
      public static void main(String[] args) {
  
          Student student1 = new Student("James Black", "07/09/1995" , new Address("Wheeler's Road",10,"Belfast", "BT12 5EG", "Co.Antrim"),StudentMode.Fulltime, false);
          Student student2 = new Student("Adam Smith", "12/11/1979" , new Address("Ivy Hill",67,"Belfast", "BT17 7BN", "Co.Antrim"),StudentMode.Parttime, true);
  
          ArrayList&lt;Person&gt; uniPeople = new ArrayList&lt;Person&gt;();
  
          uniPeople.add(student1);
          uniPeople.add(student2);
  
          printMenu(uniPeople);
  
  
  
      }
  
  
      public static void printAllDetails(ArrayList&lt;Person&gt; uniPeople) {
          for (int i = 0; i &lt; uniPeople.size(); i++) {
              System.out.println(uniPeople.get(i).toString());
          }
      }
  }
  </code></pre>
  
  <p>Output: </p>
  
  <pre><code>Student [ ID: 1002; Name: null; DOB: null; Study Mode: Fulltime; Number of Enrolled Modules: 0
  Student [ ID: 1003; Name: null; DOB: null; Study Mode: Parttime; Number of Enrolled Modules: 0
  </code></pre>
  
  <p>Can anyone help me with this problem? Thanks</p>