抽象类为什么可以有构造函数?- Constructor of an abstract class in C#(转载)


 

Why is it possible to write constructor for an abstract class in C#?
As far as I know we can‘t instantiate an abstract class.. so what is it for?
You can‘t instantiate the class, right?

 

 


 

Because there might be a standard way you want to instantiate data in the abstract class. That way you can have classes that inherit from that class call the base constructor.

public abstract class A
{

    private string data;

    protected A(string myString)
    {
        data = myString;
    }

}

public class B : A
{
    public B(string myString) : base(myString)
    {

    }

}

 

 

原文链接

 

抽象类为什么可以有构造函数?- Constructor of an abstract class in C#(转载)

上一篇:[草稿] Linux 各种 打包 / 解包 命令


下一篇:sqlserver获取当前id的前一条数据和后一条数据