代码拉取完成,页面将自动刷新
using System;
/*
C# 多重继承
多重继承指的是一个类别可以同时从多于一个父类继承行为与特征的功能。与单一继承相对,单一继承指一个类别只可以继承自一个父类。
C# 不支持多重继承。但是,您可以使用接口来实现多重继承。
*/
namespace InheritanceApplication
{
class Shape
{
protected int width;
protected int height;
public void SetWidth(int w)
{
width = w;
}
public void SetHeight(int h)
{
height = h;
}
}
// 基类 PaintCost
public interface PaintCost
{
int GetCost(int area);
}
// 派生类
class Rectangle : Shape, PaintCost
{
public int GetArea()
{
return (width * height);
}
public int GetCost(int area)
{
return area * 70;
}
}
class RectangleTester
{
static void Main(string[] args)
{
Rectangle rect = new Rectangle();
int area;
rect.SetWidth(5);
rect.SetHeight(7);
area = rect.GetArea();
// 打印对象的面积
Console.WriteLine("总面积:{0}", rect.GetArea());
Console.WriteLine("油漆总成本:${0}", rect.GetCost(area));
Console.ReadKey();
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。