Reputation:
I'm getting errors that this has an illegal start of expression and it shows just about every line as being a problem. Any help with what I'm missing here?
public abstract class Shapes
{
public static void main(String[] args)
{
protected final double pi=3.14;
//varible pi is delcared as constant
protected double radius;
protected double height;
public Shapes (double gRadius,double gHeight)
{
//sets radius, height variables to parameter values
radius=gRadius;
height=gHeight;
}
abstract public double getCircumference();
abstract public double getTotalSurfaceArea();
abstract public double getVolume();
}
}
Upvotes: 2
Views: 200
Reputation: 31
You should declare all variable, method inside class only.and all the object creation and invoking method must be do in main() method.like this public abstract class Shapes { protected final double pi=3.14;
protected double radius;
protected double height;
public Shapes (double gRadius,double gHeight)
{
//sets radius, height variables to parameter values
radius=gRadius;
height=gHeight;
}
abstract public double getCircumference();
abstract public double getTotalSurfaceArea();
abstract public double getVolume();
public static void main(String args[])
{
}
}
Upvotes: 0
Reputation: 21
Variable, methods and constructor must be declared inside the Class for which class you are declaring them, not inside the main method so move all your Variable, methods and constructor declaration inside the class from main method, then your code will be working fine.!
public abstract class Shapes{
protected final double pi=3.14;
//varible pi is delcared as constant
protected double radius;
protected double height;
public Shapes (double gRadius,double gHeight)
{
//sets radius, height variables to parameter values
radius=gRadius;
height=gHeight;
}
abstract public double getCircumference();
abstract public double getTotalSurfaceArea();
abstract public double getVolume();
public static void main(String[] args)
{
}
}
Upvotes: 0
Reputation: 394136
Your problem is that you put the contents of your class inside your main method.
Just move your main :
public abstract class Shapes
{
protected final double pi=3.14;
//varible pi is delcared as constant
protected double radius;
protected double height;
public Shapes (double gRadius,double gHeight)
{
//sets radius, height variables to parameter values
radius=gRadius;
height=gHeight;
}
abstract public double getCircumference();
abstract public double getTotalSurfaceArea();
abstract public double getVolume();
public static void main(String[] args)
{
}
}
Upvotes: 3