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
How do I run a cshtml file?
What is constants in c#?
What is type checking in c#?
Is visual c# free?
if you do have a stack overflow profile.what is your ranking?
Which is better interface or abstract class in c#?
What is datagrid c#?
In dynamic link library, which api is used for load library?
Is string a data type in c#?
How do I calculate relative time?
What do you mean by synchronous and asynchronous operations?
What is xamarin used for?
Perfect Example Of While And Do-While Loop In C#.Net ?
Explain the difference between “constant” and “read-only” variables used in c#?
What is the system namespace?