title: java inheritance Exception in thread "main" java.lang.NullPointerException
body: <p>I am new in Java. I got a question in inheritance.
  I tried to write some kinds of sorting class. They got same data structure and same methods too.
  So I tried to use inheritance.
  I wrote this base class.</p>
  
  <pre><code>public class Sort {
  private int[] lst;
  
  public Sort(int[] lst) {
      this.lst = lst;
  }
  
  public void sort() {
      return;
  }
  
  public String toString() {
      String aa = "";
      for (int innt : this.lst) {
          aa = aa + innt + "" + " ";
      }
      return aa;
  }
  }
  </code></pre>
  
  <p>and this </p>
  
  <pre><code>public class Select extends Sort{
  private int[] lst;
  
  public Select(int[] lst) {
      super(lst);
  }
  
  public void sort() {
      for (int i = 0; i &lt; this.lst.length; i++) {
          int small = lst[i];
          int small_ind = i;
          for (int j = i + 1; j &lt; this.lst.length; j++) {
              if (lst[j] &lt; small) {
                  small = lst[j];
                  small_ind = j;
              }
          }
          int temp = lst[i];
          lst[i] = small;
          lst[small_ind] = temp;
      }
  }
  }
  </code></pre>
  
  <p>but when I run this</p>
  
  <pre><code>public class Test {
  
  public static void main(String[] args) {
      int[] a = {5, 6, 7, 5, 7, 3, 2, 1, 4, 8};
      Sort sl = new Select(a);
      sl.sort();
      System.out.println(sl.toString());
  }
  }
  </code></pre>
  
  <p>It does not work. Exception in thread "main" java.lang.NullPointerException
  It only work when I move the toString method to Select class, and remove "extends Sort".
  Would you mind helping me? Thanks.</p>