Is it possible to override the constructor of the base class in the derived class?
If so, the how can it be accomplished and in what use case would this be practical? If not, why not?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, you can’t override constructors. The concept makes no sense in C#, because constructors simply aren’t invoked polymorphically. You always state which class you’re trying to construct, and the arguments to the constructor.
Constructors aren’t inherited at all – but all constructors from a derived class must chain either to another constructor in the same class, or to one of the constructors in the base class. If you don’t do this explicitly, the compiler implicitly chains to the parameterless constructor of the base class (and an error occurs if that constructor doesn’t exist or is inaccessible).