Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing parameters to the base class constructor

Tags:

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

like image 944
n.y Avatar asked May 05 '14 20:05

n.y


People also ask

Can we pass parameters to base class constructor Mcq?

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.

Can we pass parameters to base 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.

What parameters are passed to a class constructor?

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.


1 Answers

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.

like image 156
BradleyDotNET Avatar answered Oct 08 '22 22:10

BradleyDotNET