title: Accessing private variable from another class in Java
body: <p>I am using my main method from class Test and am trying to call a function in an object, Course.  This is the code from my main method:</p>
  
  <pre><code>if (decideStatus &gt; .75) {
                  status = Classification.GRAD;
                  gradCount++;
                  if (gpa &gt; 3.2) {
                      Student newStudent = new Student(sID, status, gpa);
                      **addStudentToRoster(newStudent);**
                  } else {
                      gradRejectCount++;
                  }
  </code></pre>
  
  <p>I am trying to use the addStudentToRoster function to add newStudent to the private variable </p>
  
  <pre><code>public class Course {
      private int number = 0;
      private String title = "";
      private int capacity = 0;
      //won't compile with float type for cutoff
      private float cutoff = 0;
      private ArrayList&lt;Student&gt; roster = new ArrayList&lt;&gt;();
      private ArrayList&lt;Student&gt; waitlist = new ArrayList&lt;&gt;();
  
      public Course(int number, String name, int maxSize, float cutoff) {
          //set value of private fields
          this.number = number;
          this.title = name;
          this.capacity = maxSize;
          this.cutoff = cutoff;
      }
  
      public void addStudentToRoster(Student student) {
          roster.add(student);
      }
  </code></pre>
  
  <p>The addStudentToRoster(newStudent) line has an error stating that that method is undefined for that class.  Does anyone know how I would fix this? </p>