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
What is difference between float and integer?
Can a string be null c#?
Explain inheritance in c#?
Explain how do you debug an asp.net web application?
What is the use of private constructor in c#?
What is difference between Enum and Struct?
What does dbml stand for?
What is a singleton unity?
What is a Jagged Array in C#?
Can you drink alcohol with a loop recorder?
How garbage collection deals with circular references.
What is the difference between ref & out parameters in c#?
Which program construct must return a value?
Explain static class members.
Why singleton pattern is used in c#?