运行时多态性具有方法重写,也称为动态绑定或后期绑定。它由抽象类和虚函数实现。抽象类 抽象类包含抽象方法,这些方法由派生类实现。让我们看一个实现运行时多态性的抽象类的示例 −示例 使用 System; 命名空间 PolymorphismApplication { 抽象类 Shape { public abstract int area(); } 类 Rectangle: Shape { private int length; private int width; public Rectangle( int a = 0, int b = 0) { …… 阅读更多
嵌套类是在另一个封闭类中声明的类。它是其封闭类的成员,封闭类的成员无法访问嵌套类的成员。让我们看看 C# 中嵌套类的示例代码片段 −类 One { public int num1; public 类 Two { public int num2; } } 类 Demo { static void Main() { One a = new One(); a.num1++; One.Two ab = new One.Two(); …… 阅读更多