编程实现矩形类Rectangle,该类包含长,宽等属性,几个重载的构造方法,以及计算矩形周长和面积的成员方法。

2024-11-30 05:11:51
推荐回答(1个)
回答1:

public class Rectangle {
private int w;
private int h;
public Rectangle(){
}
public Rectangle( int w, int h) {

this.w = w;
this.h = h;
}

public double area() {
double a=this.w;
double b=this.h;
return a*b;

}
}