注册 登录
编程论坛 JAVA论坛

求解答,谢谢!改了半天还是有错

小心飞刀hbw 发布于 2017-03-08 11:45, 1419 次点击
public class RectangleTest2 {
    public static void main(String[] args) {
            Rectangle obj=new Rectangle(2,3);
            System.out.println("举行的长和宽是:"+obj.length+","+obj.width);
            int result=obj.area();
            System.out.println("矩形的面积是:"+result);
            }
    }

class Rectangle()
{
    int length=1,width=1;
    public int area()
    {
        int temp=length*width;
        return temp;
    }
    public Rectangle(int x,int y){
        length=x;
        width=y;
    }
}
4 回复
#2
孤独与烈酒2017-03-08 13:29
把你的代码运行了一下 没有错
#3
梦月神游2017-03-11 19:52
回复楼主:

class Rectangle()//class 是一个类而不是类方法。后面不用加小括号。

#4
小心飞刀hbw2017-03-15 12:34
回复 3楼 梦月神游
谢谢
#5
小心飞刀hbw2017-03-15 12:35
回复 2楼 孤独与烈酒
哈哈,还是有问题的
1