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 )
   {
      super("SphereShape");
	  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

Recommended Answers

All 4 Replies

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.

A Taimoor Rana I removed the extra } and the error is gone. Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.