title: How to call a method from another class, in a class in Java
body: <p>I'm trying to use a method I've created in class <code>Student</code>, in another class, <code>Classroom</code>.  I'm wondering if it is even possible to call a method that's defined in another class, or if I'm approaching this the wrong way.</p>
  <p>class<code>Student</code>:</p>
  <pre><code>public class Student {
      String firstName;
  
      Student(String firstName){
          this.firstName=firstName;
      }
  
      public String getFirstName() {
          return firstName;
      }
  }
  </code></pre>
  <p>class <code>Classroom</code>:</p>
  <pre><code>public class Classroom{
  
      public ArrayList&lt;Student&gt; students;
  
      public Classroom(ArrayList&lt;Student&gt; studentArrayList) {
  
      }
  
      Student getStudent(ArrayList students){
          this.students=students;
          System.out.println(students.get(0).getFirstName);
          return null;
      }
  }
  
  </code></pre>
  <p><code>Main</code>:</p>
  <pre><code>public class Main {
  
      public static void main(String[] args) {
          Student a = new Student(&quot;John&quot;);
          Student b = new Student(&quot;Jane&quot;);
  
          ArrayList&lt;Student&gt; studentArrayList = null;
          studentArrayList.add(a);
          studentArrayList.add(b);
  
          Classroom c = new Classroom(studentArrayList);
  
          System.out.println(c.getStudent(studentArrayList));
      }
  }
  </code></pre>
  <p>My problem seems to be when I attempt to call the method <code>getFirstName</code>, I'm wondering is there is a way to call <code>getFirstName</code> in the <code>Classroom</code> class.  My intention for this code is to return the object <code>a</code>.</p>