First I have tried this and didn't work:
public HasWidth castToHasWidth() {
            class Inneer implements HasWidth{

                @Override
                public double getWidth() {

                    return Math.abs(point1.getX() - point2.getX());
                }
            }
            return new Inneer();
        }
After that I have tried this and it worked, it passed:
public HasWidth castToHasWidth() {
           class Inneer implements HasWidth{

               @Override
               public double getWidth() {
                   double f = point1.getX();
                   double s = point2.getX();
                   double di = Math.abs(f - s);
                   return di;
               }
           }
           return new Inneer();
       }
After runnning the second one it works even when I use the first alternative.Can anyone tell me why?