Passing parameters to the base class constructor

2020-03-10 19:41发布

问题:

If the base class and derived class both have their constructors with parameters then where we pass the parameters to the base class constructors?

回答1:

Like this:

public class DerivedClass : BaseClass
{
    public DerivedClass(int derivedParam, String baseParam):base(baseParam)
    {
    }
}

The base keyword here calls the base class constructor that matches the provided parameter overload.