title: How to construct an array in a class in java and call it?
body: <p>I am a beginning java programmer and am having some issues with constructing an array in a class and then calling it and using it. So I have a program that has 2 classes. The first is called MyDate and is meant to declare instance variables, a constructor, and then as toString() method. From there I am creating another class called DateArray that creates an array of MyDate with the name of dateArr. </p>
  
  <pre><code>package date_array;
  
  class MyDate {
      public int day;
      public String month;
      public int year;
  
      public MyDate(String month, int day, int year)
      {
          this.day = day;
          this.month = month;
          this.year = year;
      }
  
      public String toString()
      {
          return (month + " " + day + " " + year);
      }
  
      public class DateArray {
          MyDate[] dateArr = new MyDate[4];
          dateArr[0] = new MyDate("May", 16,1984);
          dateArr[1] = new MyDate("May", 16,1984);
          dateArr[2] = new MyDate("May", 16,1984);
          dateArr[3] = new MyDate("May", 16,1984);
      }
  
      public static void main(String[] args) {
          MyDate[] dateArr = new MyDate[4];
          dateArr.toString();
      }
  }
  </code></pre>
  
  <p>This is the code I have so far. I am really struggling with building the array in the DateArray class without getting exception errors and such as. I have tried moving things around into main and use different wording but with looking though my notes and many google searches later I am still completely stuck. What I really need help with is creating my array in the DateArray class, and then printing out the desired arrays to the console. Any help would be great. Thank you much!</p>