title: Java: Extending inner classes
body: <p>I am trying to understand extending inner classes in Java. I have read around but nothing I found quite answers my question. So here goes...</p>
  
  <p>I have...</p>
  
  <pre><code>public class Pie{
      protected Slice[] slices;
  
      // Pie constructor
      public Pie(int n){
           sliceGenerator(n)
      }
  
      private void sliceGenerator(int n){
           slices = new Slice[n];
           final float sweepAngle = 360.0f/(float)n;
           float startAngle = 0;
           for (int i=0;i&lt;n;i++){ 
               slices[i] = new Slice(startAngle);
               startAngle += sweepAngle;
           }
      }
  
      @Override
      public String toString(){
           for (Slice s:slices){  
               s.toString();
           }
      }
  
      // Inner class...
      public class Slice{
          public Slice(float startAngle){
               //set some private fields based on startAngle and generic pie 
          }
  
          @Override
          public String toString(){
               return **string based on private fields**
          }
      }
  }
  </code></pre>
  
  <p>Then I extend this...</p>
  
  <pre><code>public class ApplePie extends Pie{
      protected Slice[] slices;
  
      // Apple Pie constructor
      public ApplePie(int n){
           super(n);
      }
  
      // Inner class...
      public class Slice extends Pie.Slice{
          public Slice(float startAngle){
              super(startAngle);
              //set some **additional** private fields based on startAngle **specific to apple pie** appleness or something
          }
  
          @Override
          public String toString(){
               return **string based on apple pie specific private fields**
          }
      }
  }
  </code></pre>
  
  <p>Now, when I make an Apple pie and call its toString method, like so...</p>
  
  <pre><code>ApplePie ap = new ApplePie(8);
  System.out.println(ap.toString());
  </code></pre>
  
  <p>I do not get information about the apple pie slices, but information about the pie slices. It ignores my <code>toString</code> override, or more likely ignores my apple pie <code>Slice</code>. How can I arrange it such that apple pie slices refer to <code>ApplePie</code>?</p>
  
  <p>Any help much appreciated! Sorry for pie references - it is the actual class I am working with...</p>