我试图学习java,而我被卡在'类'部分。他们给了我一个问题,我不知道为什么这是错的。需要帮助解决Square Class问题,特别是代码?
我已经读了很多,我不明白为什么有大约14个错误信息?在所有...
这里的任务:
// You are to write the constructor specified for this Square class. The Square class
// has an instance variable of type double, side, which is the length of each side of
// the square. The javadoc has been provided for you to help you tell what you needs to
// be done
//
// HINT: Write the constructor for the class Square.
// The constructor will take in a parameter of the type double
// and assign that parameter to the instance variable side
这里是我的代码:
public class Square(double side)
private double side;
/**
* Constructor for objects of class Square
* @param theSide the length of the side of this Square
*/
public main(double theSide) {
side = theSide;
}
/**
* Gets the length of a side of this square
* @return the side of this square
*/
public double getSide()
{
return side;
}
Compiler error: /tmp/codecheck.XNhW00Z3c8/Square.java:12: error: '{' expected public class Square(double side)^/tmp/codecheck.XNhW00Z3c8/Square.java:12: error: ';' expected public class Square(double side)^/tmp/codecheck.XNhW00Z3c8/Square.java:31: error: reached end of file while parsing }^/tmp/codecheck.XNhW00Z3c8/Square.java:14: error: variable side is already defined in class Square private double side;^
哪里是错误?请发布错误 – abcOfJavaAndCPP
14错误,你不能打扰张贴其中之一? – John3136
这里是错误,现在他们下降到4。 –