【发布时间】:2014-07-13 23:33:28
【问题描述】:
这是我尝试创建的类:
package rectangle;
public class Rectangle
{
private double length,width;
public void setLength(double length)
{
length=this.length;
}
public void setWidth(double width)
{
width=this.width;
}
public double getLength()
{
return length;
}
public double getWidth()
{
return width;
}
public double area()
{
return length*width;
}
}
我相信我已经正确地完成了课程。我只是想创建和使用一个可以计算矩形面积的类。
然后我尝试实际创建实例对象:
/*Testing out the rectangle class*/
package rectangleclasstest;
import java.util.Scanner;
public class RectangleClassTest
{
static void main(String[] args)
{
Scanner keyboard= new Scanner(System.in);
Rectangle rec=new Rectangle();
//get length
System.out.println("Please enter the length");
rec.setLength()=keyboard.nextInt();
}
}
当我尝试创建对象 rec 作为我刚刚创建的 Rectangle 类的实例时,我不断收到错误消息。就好像程序根本找不到我刚刚制作的课程一样。任何反馈都会有所帮助。谢谢
【问题讨论】:
-
请在您的 IDE 中发布您的包视图的屏幕截图,然后我们可能会为您提供进一步的帮助。
标签: java class object netbeans instance