title: Java Collections.sort() not sorting as expected
body: <p>I am trying to sort two different ArrayLists of objects by a specific atribute ('Student' objects by "program" and 'Professor' objects by "faculty"). Both classes extend my abstract 'Person' class.</p>
  
  <pre><code>public abstract class Person implements Comparable&lt;Person&gt;{
      private String name;
      private String adress;
  
      //getters, setters, etc., all works properly
  
      @Override
      protected Object clone() throws CloneNotSupportedException {
          return super.clone(); 
      }
  
      public int compareTo(String string) {
          return name.compareTo(string);
      }
  }
  </code></pre>
  
  <p>Then, when I create an array of 1000000 random 'Person' objects than can be Students or Professors, I decide to sort it alphabetically by their name like this (which works properly).</p>
  
  <pre><code>Person personByName[] = arrayPersonas.clone();
  Arrays.sort(personByName);
  </code></pre>
  
  <p>Then, I divide the original Person array into two ArrayLists, one for Student objects and another for Professor objects:</p>
  
  <pre><code>    ArrayList&lt;Student&gt; studentsByProgram = new ArrayList();
      ArrayList&lt;Professor&gt; professorsByFaculty = new ArrayList();
      for (int i = 0; i &lt; 1000000; i++) { 
          if (arrayPersonas[i] instanceof Student) {
              studentsByProgram.add((Student)arrayPersonas[i]);
          } else {
              professorsByFaculty.add((Professor)arrayPersonas[i]);
          }
      }
  </code></pre>
  
  <p>The problem comes when i try to sort each ArrayList alphabetically by the atribute I want, since it keeps sorting them by the name of the Person:</p>
  
  <pre><code>Collections.sort(studentsByProgram);
  Collections.sort(professorsByFaculty);
  </code></pre>
  
  <p>Here I leave my Student and Professor classes:</p>
  
  <pre><code>public class Student extends Person {
      private String program;
      private int year;
      private double fee;
  
      //constructor, setters, getters, toString, equals
  
      @Override
      protected Object clone() throws CloneNotSupportedException {
          return super.clone(); 
      }
  
  
  
      public int compareTo(String string) {
          return program.compareTo(string); 
      }
  
      @Override
      public int compareTo(Person t) {
          return super.compareTo(t.getName());
      }
  }
  </code></pre>
  
  <p>Professor class:</p>
  
  <pre><code>public class Professor extends Person {
      private String faculty;
      private double salary;
  
      //constructor, setters, getters, toString, equals
  
      @Override
      protected Object clone() throws CloneNotSupportedException {
          return super.clone(); 
      }
  
  
      public int compareTo(String string) {
          return faculty.compareTo(string); 
      }
  
      @Override
      public int compareTo(Person t) {
          return super.compareTo(t.getName());
      }
  }
  </code></pre>
  
  <p>What am I doing wrong? I thought if I call "Collections.sort()" on an ArrayList of Student objects it would use the "compareTo()" method from my Student class, which uses the "program" atribute. I'm still learning to work with these methods so there is something I'm not getting.</p>