该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
public interface planeGraphics2
{
public abstract double area();
public abstract double perimeter();
public abstract void print();
}
public class rectangle2 implements planeGraphics2
{
protected double length;
protected double width;
public rectangle2(double length,double width)
{ this.length=length;
this.width=width;
}
public rectangle2(double width)
{
this.length=width;
this.width=width;
}
public rectangle2(0
{
this(0,0);
}
public rectangle2(rectangle2 r1)
{ this(r1.length,r1.width);
}
public double area()
{
return this.width*this.length;
}
public double perimeter()
{
return(this.width+this.length)*2;
}
public void print()
{
if (this.length==this.width)
system.out.println("一个矩形。边长为"+this.length);
else
system.out.print("一个长方形,长度为"+this.length+",宽度"+this.width);
system.out.println(",面积为"+this.area()+",周长为"+this.perimeter());
}
public static void main(string args[])
{
rectangle2 r1= new rectangle2(10,20);
r1.print();
r1=new rectangle2(10);
r1.print();
}
}