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
Explain the Different types of configuration files in .net?
Explain the difference between boxing and unboxing.
Explain concurrency with aop?
What is IL / CIL / MSIL?
Define c# i/o classes?
How do I run a cshtml file?
You have got 1 million parking slots. At a time a parking slot can be free or not. To get next slot easily which data structure to implement?
What is difference between class and abstract class in c#?
What are the 2 types of data types available in c#?
1. Describe page life cycle?
What is the importance of closing an ado.net application?
What is type safe code?
Explain the difference between user control and custom control. Also, explain their use.
Can a string be null c#?
Describe the difference between inline and code behind - which is best?