Java错误非法开始表达

时间:2015-09-16 05:33:12

标签: java

我得到错误,这是一个非法的表达开始,它几乎显示每一行都是一个问题。对我在这里失踪的任何帮助都有帮助吗?

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();
}
}

3 个答案:

答案 0 :(得分:3)

您的问题是您将课程内容放在主方法中。

移动你的主要:

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)
     {
     }
}

答案 1 :(得分:0)

变量方法构造函数必须在中声明您要声明它们的类,不在方法中,所以在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)
 {
 }

}

答案 2 :(得分:0)

你应该只声明类中的所有变量,方法。所有的对象创建和调用方法都必须在main()方法中进行。像这样      公共抽象类形状 {     受保护的最终双重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[])
{
} 
}