C# provides a default constructor for me. I write a
constructor that takes a string as a parameter, but want to
keep the no parameter one. How many constructors should I write?
Answer Posted / kiran
namespace SameNamespace
{
class MyBaseClass
{
protected internal int myprotectedinternalint;
private string myName;
public MyBaseClass(string abc)
{
myName = abc;
}
public MyBaseClass()
{
}
}
class MyDerivedClass:MyBaseClass
{
public int GetProtectedInternalMember()
{
return myprotectedinternalint;
}
public MyDerivedClass(int myvalue)
{
myprotectedinternalint = myvalue;
}
}
class MyTest
{
public static void Main()
{
MyBaseClass mbc = new MyBaseClass();
MyDerivedClass mdc = new MyDerivedClass(12);
Console.WriteLine(mdc.GetProtectedInternalMember
());
Console.ReadKey();
}
}
}
| Is This Answer Correct ? | 0 Yes | 1 No |
Post New Answer View All Answers
why delegate is type safe?
If I return out of a try/finally in c#, does the code in the finally-clause run?
Are c and c# the same thing?
What is state c#?
What is deferred execution in c#?
What is a nullreferenceexception?
What is lock in c#?
What is polymorphism and its types in c#?
What is a singleton unity?
What is join in c#?
What is typeof undefined?
What is the difference between do and while loop?
Can you describe iuknown interface in short?
What is a reference type c#?
What do you mean by object pooling?