Why are constructors not inherited in C#?

后端 未结 5 2124
耶瑟儿~
耶瑟儿~ 2020-11-29 07:52

I\'m guessing there\'s something really basic about C# inheritance that I don\'t understand. Would someone please enlighten me?

5条回答
  •  生来不讨喜
    2020-11-29 08:30

    Sometimes, when subclassing, you want to restrict the conditions required to create an instance of the class.

    Let me give you an example. If classes did inherit their superclass constructors, all classes would have the parameterless constructor from Object. Obviously that's not correct.

提交回复
热议问题