In your superclass, you create and save Pie.Slice objects:
private void sliceGenerator(int n){ slices = new Slice[n]; final float sweepAngle = 360.0f/(float)n; float startAngle = 0; for (int i=0;i<n;i++){ slices[i] = new Slice(startAngle); startAngle += sweepAngle; } }
These are the same objects used by Pie.toString (which ApplePie does not cancel, by the way).
Extending Pie with ApplePie and extending Pie.Slice with ApplePie.Slice does not change this. new Slice(startAngle) in the above code does not magically switch to creating something else.
In addition, your Pie.toString() does not return anything - it should not even compile:
@Override public String toString(){ for (Slice s:slices){ s.toString(); } }
I assume that you want to return a string representing all the fragments. This would be a quick fix, for example:
@Override public String toString() { return Arrays.toString(slices); }
( Arrays.toString is just a utility method for getting a string representation of an array.)
source share