子类能不能继承父类的构造方法?
程序代码:interface A
{
float perimeter();
float square();
}
class Rectangle implements A
{
float a, b;
public Rectangle(float a)
{
this.a = a;
this.b = a;
}
public Rectangle(float a, float b)
{
this.a = a;
this.b = b;
}
@Override
public float perimeter()
{
return 0;
}
@Override
public float square()
{
return 0;
}
}
class Square extends Rectangle
{
// public Square(float a)
// {
// this.a = a;
// this.b = a;
// }
public float perimeter()
{
float l = (a+b)*2;
return l;
}
public float square()
{
float s = a * b;
return s;
}
}
class M
{
public static void main(String[] args)
{
Square sq = new Square(5);
System.out.println("正方形的周长:"+sq.perimeter()+" "+"正方形的面积为:"+sq.square());
}
}







