package cube;
//矩形周长与面积
class Rectangle
{
double width;
double height;
Rectangle()
{
width=2;
height=3;
}
double length()//这是无参构造函数
{
double l=2*(width+height);
return l;
}
double getArea(double w,double h)//这是有参构造函数
{
w=this.width;
h=this.height;
double a=w*h;
return a;
}
}
public class Cube
{
public static void main(String[] args)
{
Rectangle r1=new Rectangle();
double l1=r1.length();
double a1=r1.getArea(r1.width,r1.height);
System.out.println("矩形周长为:"+l1);
System.out.println("矩形面积为:"+a1);
}
}
