If we inherit a class do the private variables also get
inherited ?
Answer Posted / sukriya
You can use private only with a nested class, one that is
defined within another class. The result is that the
private class is accessible only from within the containing
class
try this code
public class BaseClass
{
public virtual void TraceSelf()
{
Console.WriteLine("BaseClass");
Privateclass pc = new Privateclass();
pc.Self();
}
private class Privateclass
{
public void Self()
{
Console.WriteLine("PrivateClass");
}
}
}
public class SubClass : BaseClass
{
public override void TraceSelf()
{
//Privateclass pc = new Privateclass();
//pc.Self();
Console.WriteLine("SubClass");
}
}
static void Main(string[] args)
{
BaseClass obj = new BaseClass();
obj.TraceSelf(); // Outputs "BaseClass"
SubClass obj2 = new SubClass();
obj2.TraceSelf();
Console.ReadKey();
}
this is the main Program for the code
| Is This Answer Correct ? | 2 Yes | 2 No |
Post New Answer View All Answers
What is difference between ienumerable and enumerable in c#?
Explain About DTS package
Define satellite Assembly in .NET?
Can a dictionary have the same key?
What is the implicit name of the parameter that gets passed into the set method/property of a class?
Is php better than c#?
What does dbml mean?
What is the default value of singleordefault?
What is a private class in c#?
without modifying source code if we compile again, will it be generated MSIL again?
What are the advantages of using assemble language programming?
Which is faster list or dictionary in c#?
Does c# support properties of array types?
Differentiate between sqlclient oledb and providers?
How to do and Apply Themes to Datagrid,Lable,Textbox,etc., in C#.NET 2005 Windows Application? (like who we will do themes in ASP.NET using .CSS and .SKIN files). Urgent!!