title: Why does PrintStream.close() end up getting called twice?
body: <p>Somewhat to my surprise, the following code prints out "Close" twice. Running through the debugger, it seems <code>MyPrintStream.close()</code> calls <code>super.close()</code>, which ends up calling <code>MyPrintStream.close()</code> again.</p>
  
  <pre><code>    
  import java.io.*;
  
  public class PrintTest
  {
      static class MyPrintStream extends PrintStream
      {
          MyPrintStream(OutputStream os)
          {
              super(os);
          }
  
          @Override
          public void close()
          {
              System.out.println("Close");
              super.close();
          }
      }
  
      public static void main(String[] args) throws IOException
      {
          PrintStream ps = new MyPrintStream(new FileOutputStream(File.createTempFile("temp", "file")));
          ps.println("Hello");
          ps.close();
      }
  }
  </code>
  </pre>
  
  <p>Why is this happening? Should I not be extending PrintStream? </p>