您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

在 C# 中重写

2024/3/3 7:41:55发布11次查看
运行时多态性具有方法重写,也称为动态绑定或后期绑定。它是通过抽象类和虚函数来实现的。抽象类包含抽象方法,这些方法由派生类实现。
让我们看一个实现运行时多态性并与重写一起使用的抽象类的示例 -
示例using system;namespace polymorphismapplication { abstract class shape { public abstract int area(); } class rectangle: shape { private int length; private int width; public rectangle( int a = 0, int b = 0) { length = a; width = b; } public override int area () { console.writeline("rectangle class area :"); return (width * length); } } class rectangletester { static void main(string[] args) { rectangle r = new rectangle(10, 7); double a = r.area(); console.writeline("area: {0}",a); console.readkey(); } }}
以上就是在 c# 中重写的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product