创建一个shape3抽象类,内有2个抽象方法方法名分别是area-面积,zc-周长,创建一个派生类rect继承shape3,实现所有面积和周长抽象方法---矩形,创建p2对象(长=7,宽:4),调用矩形的周长和面积
时间: 2024-02-21 11:57:00 浏览: 79
```
abstract class Shape3 {
public abstract double area();
public abstract double zc();
}
class Rect : Shape3 {
public double length;
public double width;
public Rect(double length, double width) {
this.length = length;
this.width = width;
}
public override double area() {
return length * width;
}
public override double zc() {
return 2 * (length + width);
}
}
class Program {
static void Main(string[] args) {
Rect p2 = new Rect(7, 4);
Console.WriteLine("矩形的周长为:" + p2.zc());
Console.WriteLine("矩形的面积为:" + p2.area());
Console.ReadLine();
}
}
```
输出:
```
矩形的周长为:22
矩形的面积为:28
```
阅读全文