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 method and function in c#?
List some of the common data providers for ado.net framework?
Can you declare a class or a struct as constant?
When do we generally use destructors to release resources?
Is Facebook a desktop application?
How to use nullable types in .net?
Please write a program to display “welcome to bestinterviewquestion.com” in c#?
What is the relation between classes and objects?
What is writeline in c#?
What are "class access modifiers" in C#?
What are Uses of CLR
To whom a method is accesssed if it is marked as protected internal ?
How objects are stored in memory?
In a memory when you Box and Unbox a value-type what happens?
What is difference between an Structure and Class?