//矩形父类
package d922A;
public class Rect {
private double l,w;
Rect(double c,double k)
{
l=c;
w=k;
}
public double s()
{
return w*l;
}
}
///立方体类
package d922A;
public class Rect1 extends Rect {
private double h;
Rect1(double c, double k,double g) {
super(c, k);
h=g;
}
public double v()
{
return s()*h;
}
}
////主类
package d922A;
public class TestRect {
public static void main(String[] args) { Rect1 a=new Rect1(5, 6,7); System.out.println("底面积为:"+a.s()); System.out.println("体积为:"+a.v()); Rect b=new Rect(5, 6); System.out.println(b.s()); Rect c=new Rect1(5, 6,7); System.out.println(c.s()); }}
///运行结果
底面积为:30.0
体积为:210.0
30.0
30.0