java - 子类中的自制方法显示语法错误

标签 java parsing methods void

我在创建方法参数和 getArea 时遇到一些问题,它只是返回一个语法错误,我不知道为什么,最后一个括号说它在解析时到达文件末尾,只需查看一下代码,我添加了注释来显示什么有效,什么无效,如果有一条注释没有写任何问题,那么这部分代码就很好,如果它确实有问题请看一下并帮助我,我是一个新手 java 程序员,也是一个一般的新手程序员,所以请原谅我的冒犯 -XATjeffreyericgutierrezMK64

/*
 * XATJeffreyEricGutierrezMK64
 */
package rectangle;

//create subclass rectangle, and declare to variables side1 and side2
class Rectangle2 {
double side1;
double side2;

//create Rectangle constructor

Rectangle2 () {

  side1 = 8;
  side2 = 12;

}

//create height and width variables

Rectangle2 (double height, double width) {

side1 = height;
side2 = width;

//return the area of this rectangle(doesn't work)

Object.getArea(){    
return side1 * side2;  

}

//Return the parameter of this rectangle(doesn't work either)

double getParameter(){   

getParameter = side1 + side2 * 2;

return;

}

//set a new side for this rectangle(doesn't work though

void setSide(double height, double width) 

side1 = height;
side2 = width; 

}

} //says i reached the end of the file without parsing

最佳答案

这是因为你的代码很多地方都是错误的,你没有正确使用括号,使用了错误的概念。将您的代码压缩为:

class Rectangle2 {
    double side1;
    double side2;

    public Rectangle2() {
        side1 = 8;
        side2 = 12;
    }

    public Rectangle2(double height, double width) {
        side1 = height;
        side2 = width;
    }

    public double getArea() {
        return side1 * side2;
    }

    double getParameter() {
        return side1 + side2 * 2;
    }

    public void setSide(double height, double width) {
        side1 = height;
        side2 = width;
    }

}

并尝试分析你的错误

关于java - 子类中的自制方法显示语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29996359/

相关文章:

java - 如何打印出正确的输出

java - 如何检查 Android 设备的架构并显示它们?

java - 在 java 中将 Integer 或 String 数组作为参数传递

python - 调用类内部的函数来设置列表的元素

Python:如何动态更改 dict 和 list 对象的方法?

java - 使用 OnboardingSupportFragment 时内容重叠

php - php中的json解析响应

c# - 如何解析数组中的 Json 对象?

java - java解析字符串以删除空格

java - 为什么我不能在类之外的方法中使用数组?