What are the keywords used to pass parameters to
the base class and how do I invoke other constructors.

Answer Posted / radhika

using base keyword we can pass parameters to the baseclass.
When an instance of the DerivedClass is created.The default
constructor in BaseClass is first invoked followed by the
DerivedClass . However, you
can choose which constructor you want to invoke in
BaseClass by using the base keyword in the
default constructor in DerivedClass , like this:

public class BaseClass
{
//---default constructor---
public BaseClass()
{
Console.WriteLine(“Default constructor in BaseClass”);
}
//---parameterized constructor---
public BaseClass(int x)
{
Console.WriteLine(“Parameterized Constructor in BaseClass”);
}
}

public class DerivedClass : BaseClass
{
//---default constructor---
public DerivedClass(): base(4)
{
Console.WriteLine(“Constructor in DerivedClass”);
}
}

Is This Answer Correct ?    5 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do you declare a variable in c#?

516


What is datatable and dataset in c#?

480


In .NET how can you solve the DLL Hell problem?

669


What benefit do you get from using a primary interop assembly (pia)?

513


What is a protected class in c#?

488






Is enum a value type c#?

524


Are private members inherited in c#?

562


What is sqldataadapter in c#?

487


Can a class have more than 1 destructor?

511


What are native methods?

482


How many types of collections are there in c#?

480


How many constructors can a class have in c#?

477


What is hierarchical inheritance in c#?

485


What are cookies in c#?

540


windows c# using datagridview in edit form sql server

3569