package javahomework; public class HW14 { class Rectangle { private double length1, length2; public Rectangle() { length1 = 1.0; length2 = 1.0; } public Rectangle(double n) { length1 = n; length2 = n; } public Rectangle(double n1, double n2) { length1 = n1; length2 = n2; } public void set(double n1, double n2) { length1 = n1; length2 = n2; } public double getL1() { return length1; } public double getL2() { return length2; } public double findArea() { return length1 * length2; } public double find4Length() { return (length1 + length2) * 2; } } class AdRectangle extends Rectangle { private double hight; AdRectangle() { hight = 1.0; } AdRectangle(double n1, double n2, double n3) { super(n1, n2); hight = n3; } public void set(double n1, double n2, double n3) { super.set(n1, n2); hight = n3; } public double findVolume() { return super.findArea() * hight; } public double findArea() { return super.getL1() * super.getL2(); } public double findFaceArea() { return super.findArea() * 2 + super.getL1() * hight * 2 + super.getL2() * hight * 2; } } }
2008年8月29日 星期五
定義一個父矩形,子長方體並繼承
code
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言