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

Is arraylist faster than linkedlist?

489


How will you get the different language strings?

505


What is the use of properties window?

495


What is the default value of object in c#?

451


What is variable in c#?

510






Does c# have primitives?

474


How many types of polymorphism are there?

496


Is it possible to force garbage collector to run?

480


What is the difference between static class and sealed class in c#?

461


What are delegate methods?

465


What are the steps for creating clr trigger

563


What is mvc in c#?

457


How does dictionary work in c#?

471


What is private variable?

482


Where static variables are stored?

470