在本文中,我们将讨论C#中的抽象类以及它将如何在C#中实现。
具有至少一个抽象方法或者成员的任何类都成为抽象类。
我们无法创建只能继承的抽象类的对象。
将是一个继承抽象类的子类是必须定义基类的所有抽象成员。
派生类应该实现抽象类的所有抽象成员,否则必须被声明为抽象类。
如果我们不会将类视为具有至少一个抽象方法的摘要,则编译器将生成错误。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace absclass
{
class Program
{
static void Main(string[] args)
{
cls obj = new cls();
obj.show();
obj.msg();
Console.ReadLine();
}
}
public abstract class student
{
public abstract void msg();
public void show()
{
Console.WriteLine("This is show method");
}
}
public class cls : student
{
public override void msg()
{
Console.WriteLine("This is msg method");
}
}
}
日期:2020-04-11 22:50:13 来源:oir作者:oir
