What are the keywords used to pass parameters to
the base class and how do I invoke other constructors.
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / varish
Class Base
{
Base(int i)
{
}
}
class child
{
child(int i):base(i)
{
}
}
| Is This Answer Correct ? | 5 Yes | 1 No |
Answer / ram
Class Base
{
Base(int i)
{
}
}
class child
{
child(int i):Base(i)
{
}
}
| Is This Answer Correct ? | 2 Yes | 0 No |
Why are there five tracing levels in System.Diagnostics.TraceSwitcher?
Can we inherit private class in c#?
Which is faster hashtable or dictionary?
what are nullable types in c#
Why data types are important?
What is difference between singleordefault and firstordefault?
What is property c#?
What is check/uncheck?
How can I check the type of an object at runtime?
How can I access the registry from c# code?
What is a system lock?
I was trying to use an out int parameter in one of my functions. How should I declare the variable that I am passing to it?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)