title: Extending private class in Java
body: <p>I found the following program puzzling:</p>
  
  <pre><code>package package1;
  
  public class Main {
      private static class A { }
  
      public static class B extends A { }
  }
  
  // ----------------
  package package2;
  
  
  public class Test {
      public static void main(String[] args) {
          Main.B b = new Main.B();
      }
  }
  </code></pre>
  
  <p>Why Java allows public class <code>B</code> to extend private class <code>A</code>? In other languages e.g. C# class may only extend private class when it is private itself.</p>
  
  <p>Can you provide any scenario when extending private class may be useful?</p>