首页 > Windows开发 > 详细

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

时间:2020-04-22 10:11:14      阅读:77      评论:0      收藏:0      [点我收藏+]


 

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#(转载)

原文:https://www.cnblogs.com/OpenCoder/p/12749236.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!