矩形类 再编写一个正方形类继承矩形(注意super用法)
class Retangle
{
public Retangle(double l,double w)
{length=l;
width=w;}
public double calcPerimeter()
{return 2*length+2*width;}
public double calcArea()
{return length*width;}
public void Show()
{System.out.println("长为"+length+"宽为"+width+"的矩形");}
protected double length;
protected double width;
}
class Square extends Retangle
{
public Square(double side)
{super(side,side);}
public double calcPerimeter()
{return width*4;}
public void Show()
{System.out.println("边长为"+width+"的正方形");}
}
class Test1
{
public static void main(String[] args)
{
Square sq1=new Square(2.0);
sq1.Show();
System.out.println("正方形周长为"+sq1.calcPerimeter());
}
}