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


Please Help Members By Posting Answers For Below Questions

Explain about Threading Types.

591


Define sealed classes in c#?

505


What are sorted lists?

494


What is c# most used for?

557


What are custom exceptions? Why do we need them?

514






How does substring work in c#?

474


What is difference between assembly and dll?

472


What is a partial method?

488


What does int32 mean?

471


Is list ienumerable c#?

597


What is type checking in c#?

503


Is c# good for games?

471


Explain how is the dll hell problem solved in .net?

453


How do you use nullable?

491


Is python easier than c#?

489