In .NET can a class have virtual constructor?

前端 未结 7 1763
别跟我提以往
别跟我提以往 2020-12-15 04:35

Can a class have virtual constructor??

If yes, why it is required?

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-15 05:14

    Declaring something virtual means that it can be overridden by a sub-class of the current class. However the constructor is called when a class is instantiated. At that time you can not be creating a subclass of the class in question so there would never be any need to declare a constructor virtual.

提交回复
热议问题