If the base class and derived class both have their constructors with parameters then where we pass the parameters to the base class constructors?
Can we pass parameters to base class constructor though derived class or derived class constructor? Explanation: Yes, we pass parameters to base class constructor though derived class or derived class constructor.
The base keyword can be used with or without parameters. Any parameters to the constructor can be used as parameters to base , or as part of an expression.
This method has four parameters: the loan amount, the interest rate, the future value and the number of periods. The first three are double-precision floating point numbers, and the fourth is an integer.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With