我在创建methods参数和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/