When you inherit a protected class-level variable, who is it
available to?
Answer Posted / kiran
//When you inherit a protected class-level variable, who is
it available to?
//Answer is classes within the same namespace
namespace SameNamespace
{
class MyBaseClass
{
protected int myprotectedint;
}
class MyDerivedClass:MyBaseClass
{
public int GetProtectedMember()
{
return myprotectedint;
}
public MyDerivedClass(int myvalue)
{
myprotectedint = myvalue;
}
}
class MyTest
{
public static void Main()
{
MyDerivedClass mdc = new MyDerivedClass(12);
Console.WriteLine(mdc.GetProtectedMember());
Console.ReadKey();
}
}
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
How do generics work in c#?
Is void a class?
Classes and structs can be declared as static, is this statement true or false?
Is the following code legal?
What are delegates in C#?
How do you comment out code in c#?
Explain hash table in c# ?
Which is the base class in c#?
What is use of a HashTable in .NET?
Why are c# strings immutable?
Is c# a backend language?
what is inheritance and an example in vb.net and c# of when you might use it?
Is array reference type in c#?
What is namespace explain with example?
Why do we need constructor in c#?