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
Which framework is best for desktop application?
If casting fails what type of exception is thrown?
Is array reference type in c#?
What is view state c#?
code for arranging given number in possible permutation ways ex:123,321,312,132,231,213.
Which namespace is required to implement trace ?
What can you do as a .net developer?
What is the benefit of interface in c#?
Why constructor is used in c#?
List the two important objects of ado.net and also list the namespaces that are commonly used in ado.net to aid in connection to a database.
What is difference between array and arraylist in c#?
How does bitwise work?
Explain the different types of delegates used in c#.
What is the file extension for c#?
What is monitor in C#?