Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Why data types are important in c#?

919


What are the different types of classes in c#?

929


What is entity framework c#?

849


Define an array?

909


What is strong name in c# and how can we use it?

938


What is join in c#?

914


What is integer c#?

894


Define property in c#.net?

943


Distinguish between a class and struct?

904


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

909


Explain the Abstract class in c#.net

989


Explain Constructor and destructor?

942


What is the difference between Singleton design pattern and Factory design pattern?

942


Is dll a library?

903


What is a struct in C#?

963