Hi am working on a shape inheritance hierarchy and am having trouble with this particular class I have two errors that state class, interface, or enum expected: on the lines indicated in red everything else seems fine I have attached the whole project If you need to check out other parts to it. Here is my code for this particular class

// Exerciae 10.9: SphereShape.java
// Sphere Shape class extends ThreeDimensionalShape.

public class SphereShape extends ThreeDimensionalShape
   private double radius; // sphere radius

   // constructor
   public SphereShape(double radius )
	  this.radius = radius;

      double volume = ( 4.0 / 3.0 ) * Math.PI * Math.pow( radius, 3 );

   } // end method sphereVolume
   } // end constructor

  // return String representation of Sphere object

   public String toString()
      return String.format( "This is a sphere. It's radius = %f. It's volume = %f\n", radius, volume);
} // end method toString
} // end class SphereShape
7 Years
Discussion Span
Last Post by Taimoor Rana

You need to remove: } // end method sphereVolume.
This is an extra brace which is causing the error.

let me know if it fix the issue

} // end method sphereVolume
   } // end constructor

There's no method "sphereVolume", so one of these ends the constructor and the other ends the class.

Edited by jon.kiparsky: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.