您好,欢迎访问一九零五行业门户网

C# 中的抽象是什么?

抽象和封装是面向对象编程中相关的特性。抽象允许使相关信息可见,而封装使程序员能够实现所需的抽象级别。
可以使用 c# 中的抽象类来实现抽象。 c# 允许您创建用于提供接口的部分类实现的抽象类。当派生类继承它时,实现就完成了。抽象类包含抽象方法,这些方法由派生类实现。派生类具有更专门的功能。
以下是一些关键点 -
您无法创建抽象的实例class
不能在抽象类之外声明抽象方法
当一个类被声明为sealed时,它就不能被继承,抽象类不能声明为密封的。
示例 实时演示
using system;namespace demo { 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(20, 15); double a = r.area(); console.writeline("area: {0}",a); console.readkey(); } }}
输出rectangle class area :area: 300
以上就是c# 中的抽象是什么?的详细内容。
其它类似信息

推荐信息